Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select records in a table where the FK ID shows up multiples?

Status
Not open for further replies.

tokuzumi

Programmer
Sep 16, 2002
40
US
This isn't as easy as the title makes it out to sound. I have a table, which we will call Table1. Table one is structured like this;

Id (Primary Key, Unique Identity, Integer)
ID_2 (Foriegn Key, Integer)
Space1 (Integer)
Space2 (Integer)
Space3 (Integer)

Now, the Foriegn Key, ID_2, should only have on record in this table, but in some cases, it has multiple records, due to glitches in our network. I would like to select all the records where the foriegn key has more than one record. Can it be done? Thanks for any help.
 
select * from table1
where id_2 in (
select id_2 from table1
group by id_2
having count(*) > 1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top