Link to home
Create AccountLog in
Avatar of thenrich
thenrich

asked on

SQL question

I have a table that has a column called 'SecondItemNumber'

How can I return a result-set that returns all duplicate records where SecondItemNumber = SecondItemNumber

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
if you have a "primary key" or "unique key" field (which will not be secondItemnumber obviously), here a alternative:
select t.*
  from yourtable t
 where exists ( select null from yourtable i where i.secondItemnumber = t.secondItemnumber  and i.that_primary_key <> t.that_primary_key )

Open in new window

note: in any case, a index on the field secondItemnumber will be required for a good performance...