Thread: sorting table
View Single Post

   
  #2 (permalink)  
Old 03-01-2008, 02:04 PM
Plamen Ratchev
 
Posts: n/a
Default Re: sorting table

Please don't multipost, rather crosspost. Replied in
microsoft.public.sqlserver.server:

SELECT F.ID,
F.LASTNAME
FROM Foobar AS F
LEFT OUTER JOIN
(
SELECT ID,
MIN(LASTNAME) AS GRP
FROM Foobar
WHERE ID > 0
GROUP BY ID
) AS G
ON F.ID = G.ID
ORDER BY COALESCE(G.GRP, F.LASTNAME),
F.ID,
F.LASTNAME

HTH,

Plamen Ratchev
http://www.SQLStudio.com



Reply With Quote