[thelist] Finding NON-unique values in MS SQL

Anthony Baratta Anthony at Baratta.com
Wed Jul 3 17:07:00 CDT 2002

At 02:54 PM 7/3/2002, Joel Canfield wrote:
>I have a table with three columns, ID, IDF, and IDT. All are integers. No
>number should be repeated in any particular column, although a number could
>conceivably appear in both IDF and IDT. I've added unique constraints, but
>if I recall correctly, when we realized that uniqueness was required,
>someone foolishly decided to add the constraint with no check on the
>existing data.
>I'm trying to come up with a query which would simply list all entries which
>appear in any particular column more than once. I'm stumped. It should be
>simple, I thought.

Select ID From TableName WHERE
  ID in (Select IDF from TableName)

Select ID From TableName WHERE
  ID in (Select IDT from TableName)

Or something like that.

Anthony Baratta
Keyboard Jockeys

"Conformity is the refuge of the unimaginative."

More information about the thelist mailing list