SQL - Select semi-duplicate rows?

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 2
Reputation: walkermat is an unknown quantity at this point 
Solved Threads: 0
walkermat walkermat is offline Offline
Newbie Poster

SQL - Select semi-duplicate rows?

 
0
  #1
Sep 2nd, 2008
Daft subject header, but its early and brain not awake yet!

One for the SQL gurus (either that i've missed something here....lol)

I want to select rows where there are duplicates of data in some columns, but not others. Where a duplication IS found, i want to return all rows involved....

Table
A B C
1 w m
1 w n
1 x m
1 x n
2 x p
2 x q
2 y o
3 y r
3 z s
4 y t
5 z v


So i want to select:-
A B C
1 w m
1 w n
1 x m
1 x n
2 x p
2 x q

The selection contains all rows where there are duplicates of data in Column A and Column B. Reckon it could include a nested select statement perhaps with a 'Count > 1' in it somewhere; but just cant see it.....

Hoping its not too 'simple' and thanks for looking!

Mat
Last edited by walkermat; Sep 2nd, 2008 at 7:51 pm. Reason: Added some more words....
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 42
Reputation: huangzhi is an unknown quantity at this point 
Solved Threads: 13
huangzhi huangzhi is offline Offline
Light Poster

Re: SQL - Select semi-duplicate rows?

 
0
  #2
Sep 6th, 2008
Try this code below:

  1. SELECT *
  2. FROM #tmpX X inner join (select A, B from #tmpX group by A, B having count(*) > 1) Y on
  3. X.A = Y.A AND X.B = Y.B
Hence Wijaya
www.ex-Soft.tk
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC