| Author |
Topic |
|
fogofogo
Starting Member
11 Posts |
Posted - 2008-11-13 : 10:23:13
|
| Hello I have a table that contains duplicate records. When users query this table, I want to filter out the duplicates. The problem is, I'm not allowed to delete records form the table, so I needed to come up with another way of doing this.So, I thought maybe I could create a view, delete the duplicates from that, and return the results to the user. Would that be the best way to do it?In the stored proc I was going to do the following...1. create a view and select the master table2. select the new view table3. remove the dups4. select the results5. delete the viewIs it possible to dp all that from 1 stored proc?Another question... there is only going to be a few people who will use this query, but there is a chance that 2 users will try to use the stored proc/view at the same time. Will this lead to data issues? The reason I ask is, if user1 calls the sp and creates the view, and user2 comes in and calls it again. As both views are the same name, will it still work?Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
fogofogo
Starting Member
11 Posts |
Posted - 2008-11-13 : 10:27:46
|
| that was quick! Thanks. I'll have a look at that link.Sorry I should have mentioned. Its a sql 2000 database. This office is stuck in the past! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-13 : 10:29:39
|
quote: Originally posted by fogofogo that was quick!Sorry I should have mentioned. Its a sql 2000 database. This office is stuck in the past!
Ok. even then no need of view. you can use temporary table with identity column to achieve this. if you can provide some sample duplicate data and explain what unique values you want out of them, i will show you query. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-13 : 10:30:46
|
| Also in future please post questions only in relevant forum. This is 2005 forum. you must have posted this in 2000 forum. |
 |
|
|
fogofogo
Starting Member
11 Posts |
Posted - 2008-11-13 : 10:36:47
|
| Thanks againHeres some sample dataID.....Fname.....Lname.....Add1 1 .....James.....Brown ....21 GetDown St 2 .....John .....Cash .....14 Jacksonville 3 .....J.........Brown ....21 GetDown St 4 .....Micky ....Jackson ..Shamone Road 5 .....Dolly ... Parton ...Cannes, France Ok so you can see from above that reocrd 1 and 3 are basically the same record. So I only want to select one of those (either). So I thought I'd need to group by last name and the address. But I also need to select the first name. Group by woudnt let me query like thisselect lname, fname, add1 from table group by fname, add1for obvious reasons. |
 |
|
|
fogofogo
Starting Member
11 Posts |
Posted - 2008-11-13 : 10:37:21
|
quote: Originally posted by visakh16 Also in future please post questions only in relevant forum. This is 2005 forum. you must have posted this in 2000 forum.
whoops! sorry |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-13 : 10:42:27
|
quote: Originally posted by fogofogo Thanks againHeres some sample dataID.....Fname.....Lname.....Add1 1 .....James.....Brown ....21 GetDown St 2 .....John .....Cash .....14 Jacksonville 3 .....J.........Brown ....21 GetDown St 4 .....Micky ....Jackson ..Shamone Road 5 .....Dolly ... Parton ...Cannes, France Ok so you can see from above that reocrd 1 and 3 are basically the same record. So I only want to select one of those (either). So I thought I'd need to group by last name and the address. But I also need to select the first name. Group by woudnt let me query like thisselect lname, fname, add1 from table group by fname, add1for obvious reasons.
SELECT ID, Fname, Lname, AddlFROM(SELECT ID, Fname, Lname, Addl, (SELECT COUNT(*) FROM YourTable WHERE Lname=t.Lname AND Addl=t.Addl AND ID<=t.ID) AS SeqFROM YourTable)tWHERE t.Seq=1 |
 |
|
|
|