Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
MichelleMA
Starting Member
32 Posts |
Posted - 2009-01-22 : 10:58:00
|
Hi, can someone please suggest a way to do this query, I know only one expression can be specified in the select distinct list, but I can't figure out how to isolate the distinct A, B columns combination from the table without creating a temp table:SELECT A, COUNT(B) FROM TABLEXGROUP BY AHAVING COUNT(B)>1AND A IN (SELECT DISTINCT A, B FROM TABLEX) |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-22 : 11:00:21
|
did you mean this?SELECT A, COUNT(DISTINCT B) FROM TABLEXGROUP BY AHAVING COUNT(DISTINCT B)>1 |
|
|
MichelleMA
Starting Member
32 Posts |
Posted - 2009-01-22 : 13:06:45
|
Yes, thank you! Is there a way to return the B column in the selection? Thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-22 : 13:10:21
|
yup. like thisSELECT t1.A,t1.B,t2.BDistCountFROM TABLEX t1INNER JOIN(SELECT A, COUNT(DISTINCT B) AS BDistCount FROM TABLEXGROUP BY AHAVING COUNT(DISTINCT B)>1)t2ON t2.A=t1.A |
|
|
MichelleMA
Starting Member
32 Posts |
Posted - 2009-01-22 : 17:10:50
|
That's exactly what I needed! Thank you so much for your help! |
|
|
|
|
|