OT Need some help with a SQL select statement
I have afield that holds unique #'s in a table. When you do a select on this field for a particular number, it should return ONLY 1 row all the time.
I've got duplicate numbers right now, so I need to find all the rows where these dupes occur, but I only want to return these rows. So how can i design my select statement so it will only show me all the duplicate instances rows?
SELECT DISTINCT * FROM tb_tablename
Then, take those query results and insert them into a new table....I'm not sure how to write that part of it.
If the records containing dupe ID's have different info in them (but the same ID)...then you're kinda screwed. there is no way to automate which record is valid, unless you have a date field that tells when the right or wrong record was put in, or something similar, that you could query, to weed out the wrong fields.
select keyfield
into temptable
from table
group by keyfield
having count(*) > 1
select t.* from table t, temptable r
where t.keyfield = r.keyfield
drop table temptable
Trending Topics
select table1.*
from thetable table1, thetable table2
where table1.field = table2.field AND table1.field2 <> table2.field2
;
Bringing Audi to Life for Audi Fans


