| | |
SQL - Select semi-duplicate rows?
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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....
•
•
Join Date: Feb 2008
Posts: 42
Reputation:
Solved Threads: 13
Try this code below:
MS SQL Syntax (Toggle Plain Text)
SELECT * FROM #tmpX X inner join (select A, B from #tmpX group by A, B having count(*) > 1) Y on X.A = Y.A AND X.B = Y.B
Hence Wijaya
www.ex-Soft.tk
www.ex-Soft.tk
![]() |
Other Threads in the MS SQL Forum
- Previous Thread: SQL2005 Installation
- Next Thread: Sort Null values at top
| Thread Tools | Search this Thread |





