Reputation: 25
I want my result set to include only one column, but I'm using a different column to group by and order by. Can I somehow, after selecting and order by removing the column from the result set?
Using MSSQL2008
Upvotes: 0
Views: 4805
Reputation: 21766
You do not have to select all the columns your order or group by, you can just select the column you want.
SELECT A
FROM dbo.Table
GROUP BY A,B
ORDER BY A,B
Upvotes: 0
Reputation: 20489
Just add another SELECT
around your query, like so:
SELECT
sum_columnB
FROM
(SELECT
columnA
, SUM(columB) sum_columnB
FROM Table
GROUP BY columnA
ORDER BY columnA
, sum_columnB) resultset
But if you would post your query, my answer could be more specific and maybe clearer.
Upvotes: 5