Selecting Duplicate Rows in A Table….

August 15, 2007

I knew this before but couldnt recall it when I needed it…. so  I am posting it here……(credit goes to vhikida@inreach.com )

Problem : 

TABLE_A has columns x and y. You want to select duplicate rows from that table

Solution :

 select * from TABLE_A where (x,y) IN (SELECT x, y FROM TABLE_A m2 GROUP BY x,y HAVING COUNT(*) > 1)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: