You have an aggregation query that returns one row. Just as a note, this query works in MySQL but would fail in most databases. The column car
is not in a group by
. Even though you are choosing only one value, SQL engines don't usually allow this (MySQL is an exception).
The query that you want is:
SELECT car, COUNT(car) AS number_of_cars
FROM cars
group by car;
Note that car
appear both in the select
and group by
. Although you could have car_id
in the group by
. this is bad form. Try to be sure that the unaggregated columns in the select
are always in the group by
-- at least until you really understand what you are doing with SQL.