MySQL如何返回唯一/不同的结果? [英] MySQL How to Return Unique/Distinct Results?
本文介绍了MySQL如何返回唯一/不同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行以下MySQL查询,以查找没有手册(且车轮有黑轮等)的汽车
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)
查询的结果看起来正确,但是它两次返回ID为27的汽车.如何更改查询,使所有结果都是唯一的(无重复)?
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)?
推荐答案
您可以尝试使用 SELECT DISTINCT
代替 SELECT
You could try SELECT DISTINCT
instead of SELECT
这篇关于MySQL如何返回唯一/不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文