Alex Chaplianka February 2016

Remove a column after selection with SQL

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

Answers


Radu Gheorghiu February 2016

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.


Jaco February 2016

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

Post Status

Asked in February 2016
Viewed 3,983 times
Voted 8
Answered 2 times

Search




Leave an answer