Search code examples
sqlsql-serverdistinct

How to use DISTINCT when I have multiple column in SQL Server?


I have the following query:

SELECT carBrand, carYear, carModel
FROM Cars;

What I want is to get only different car names.

I wrote this, but it is not what I want:

SELECT DISTINCT carBrand, carYear, carModel
FROM Cars;

How can I solve this problem?


Solution

  • Try thi:

    SELECT carBrand, carYear, carModel 
    FROM Cars 
    GROUP BY carBrand, carYear, carModel;