how to use DISTINCT when I have multiple column in sql server

后端 未结 4 1681
半阙折子戏
半阙折子戏 2020-12-16 02:04

I have the following query:

select carBrand, carYear, carModel from cars;

what I want is to get only different car names.

I wrote t

4条回答
  •  忘掉有多难
    2020-12-16 02:49

    It depends what you want. For example if you want 'Toyota Corolla' and 'Toyota Camry', but ignore the year, then you could do this:

    SELECT DISTINCT carBrand + ' ' + carModel AS carName
    FROM Cars;
    

提交回复
热议问题