MySQL How to Return Unique/Distinct Results?

ma11hew28 picture ma11hew28 · Jan 11, 2011 · Viewed 16.8k times · Source

I'm running the following MySQL query to find cars that don't have manuals (and have black wheels, etc.)

SELECT `cars`.* FROM `cars`
INNER JOIN wheels ON cars.id = wheels.car_id
LEFT OUTER JOIN manuals ON cars.id = manuals.car_id
WHERE (cars.created_at > '2010-09-09'
AND wheels.color = 'Black'
AND wheels.created_at < '2011-01-05'
AND manuals.car_id IS NULL)

The results of the query look correct, but it returns the car with id 27 twice. How do I change the query so that all results are unique (no duplicates)?

Answer

user571545 picture user571545 · Jan 11, 2011

You could try SELECT DISTINCT instead of SELECT