October 9, 2006 at 12:23 pm
I have this table with:
columna columnb
26806 26804
26806 42485
10701 10401
10701 10402
10701 10403
10701 10404
How should I build the query so that it will return just 1 record for 26806 and 10701?
Thanks for helping me.
October 9, 2006 at 12:29 pm
SEELCT ColumnA,MIN(ColumnB) OR MAX(ColumnB)
FROM tblXYZ
GROUP BY ColumnA
Ram
October 9, 2006 at 12:47 pm
Thanks Sriram.
What if I have several more columns after columnb? I tried your query when I have several columns after columnb and the query didn't work.
October 9, 2006 at 12:56 pm
Here's one way:
SELECT top 2 columna, columnb , DENSE_RANK() OVER (PARTITION BY columna ORDER BY columnb) AS DENSE_RANK
FROM yourTable
ORDER BY dense_rank
******************
Dinakar Nethi
Life is short. Enjoy it.
******************
October 9, 2006 at 5:01 pm
Try this out (If you have more columns)
SELECT A.*
FROM tblXYZ AS A
INNER JOIN (
SELECT ColumnA,MIN(ColumnB) AS ColumnB
FROM tblXYZ
GROUP BY ColumnA
  AS B
ON A.ColumnA = B.ColumnA
AND A.ColumnB = B.ColumnB
Ram
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply