Click here to Skip to main content
16,015,351 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
ID Vehicle_Color
1234 Red
2345 Blue
3456 Black
4567 Red
5678 White

How do I list just the red-colored cars?

What I have tried:

I've tried to use select count (distinct vehicle_color='red'
Posted
Updated 2-Jun-23 10:51am
Comments
Dave Kreskowiak 2-Jun-23 15:32pm    
You might also want to read up on the documentation for DISTINCT and SELECT WHERE clauses. You don't need DISTINCT to do this at all.

 
Share this answer
 
The general form of an SQL query is:
SQL
SELECT <columns list> FROM <Table name> WHERE <condition>
For example to find all the red cars you might use:
SQL
SELECT * FROM Cars WHERE Colour = 'Red'

So the first thing you need to do is use something like that to find all the records you are interested in.

When you can get them - and only them - you can use use an aggregate function as Richard has suggested in place of the columns list.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900