I am learning databases and I'm hitting an issue and I want someone to explain it to me. I have a table.
car | car_id | car_type
________________________________
bmw | 1 | <bmwcartype1>
bmw | 1 | <bmwcartype2>
bmw | 1 | <bmwcartype3>
bmw | 1 | <bmwcartype4>
mercedes| 2 | <mercedescartype1>
mercedes| 2 | <mercedescartype2>
mercedes| 2 | <mercedescartype3>
lexus | 3 | <lexuscartype1>
lexus | 3 | <lexuscartype2>
lexus | 3 | <lexuscartype3>
lexus | 3 | <lexuscartype4>
lexus | 3 | <lexuscartype5>
I want to display for example the car and the number of cartypes. I'm not sure how to explain this but on the table above I only managed to get the first row.
SELECT car, COUNT(car) AS number_of_cars FROM cars WHERE car_id = 1
This is displaying the first row like:
car | number_of_cars
bmw | 4
And I want the following rows to be:
car | number_of_cars
bmw | 4
mercedes | 3
lexus | 5
How can I do that?
whereclause, addgroup by car.