SELECT DISTINCT car_year
FROM cars
ORDER BY car_year
SELECT DISTINCT car_make
FROM cars
ORDER BY car_make
How to select distinct rows in 2 columns and sort both individually
-
11-06-2023 - |
Question
I have this sql:
SELECT DISTINCT car_year, car_make
FROM cars
GROUP BY car_year, car_make
ORDER BY car_year ASC, car_make ASC
It returns this:
car_year | car_make
-------------------
2009 | TOYOTA
2011 | AUDI
2013 | ACURA
2014 | AUDI
2015 | KIA
2015 | ACURA
I need it to be more unique (distinct) and almost make it as individual lists, even though these are stored in same table (cars). Something like this:
car_year | car_make
-------------------
2009 | ACURA
2011 | AUDI
2013 | KIA
2014 | TOYOTA
2015 |
La solution
Autres conseils
try this
SELECT car_year, car_make
FROM <tablename>
GROUP BY car_make, car_year
ORDER BY car_year ASC, car_make DESC
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow