quote: Originally posted by sqlclarify I know I asked this question before but I can't find it.. and I have this problem again.. Lets say I have SELECT COLA,COLB,COLC,COLQ,FROM xyz....I need to group by only COLA AND COL B. But according to the syntax I have to list all the columns. But if I do that it changes the meaning of the grouping. How do I avoid that? How do I get by this problem?Thank you.
Yup. As you told when you group by COLA & COLB you can obviously bring only single set of values for other columns along with it. which value will you be interested in? first,last or random?1.SELECT COLA,COLB,....FROM(SELECT ROW_NUMBER() OVER (PARTITION BY COLA,COL B ORDER BY IDCol) AS Seq,COLA,COLB,COLC,COLQ,FROM xyz....)tWHERE Seq=12.SELECT COLA,COLB,....FROM(SELECT ROW_NUMBER() OVER (PARTITION BY COLA,COL B ORDER BY IDCol DESC) AS Seq,COLA,COLB,COLC,COLQ,FROM xyz....)tWHERE Seq=13.SELECT COLA,COLB,....FROM(SELECT ROW_NUMBER() OVER (PARTITION BY COLA,COL B ORDER BY NEWID()) AS Seq,COLA,COLB,COLC,COLQ,FROM xyz....)tWHERE Seq=1 IDCol is unique valued column in your table |