本文介绍了SQL查询中没有重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SELECT DISTINCT tblcaritem.caritemid,tblcar.icarid
FROM tblcaritem
INNER JOIN tblprivatecar ON tblcaritem.partid = tblprivatecar.partid
INNER JOIN tblcar ON tblcaritem.carid = tblcar.carid
WHERE tblcaritem.userid = 72;
有时我得到重复的tblcaritem.caritemid的结果。我想确保永远不会得到重复的tblcaritem.caritemid,但我该怎么办?我试图使用DISTINCT,但它只是检查整行是否重复,我想检查只有tblcaritem.caritemid,有没有办法?
对不起,如果我没有解释很好,我不是SQL查询中最好的。
解决方案
GROUP BY tblcaritem.caritemid
I'm doing a select in MySQL with an inner join:
SELECT DISTINCT tblcaritem.caritemid, tblcar.icarid
FROM tblcaritem
INNER JOIN tblprivatecar ON tblcaritem.partid = tblprivatecar.partid
INNER JOIN tblcar ON tblcaritem.carid = tblcar.carid
WHERE tblcaritem.userid=72;
Sometimes I get duplicates of tblcaritem.caritemid in the result. I want to make sure to never get duplicates of tblcaritem.caritemid, but how can I do that? I tried to use DISTINCT but it just checked if the whole row is a duplicate, I want to check for only tblcaritem.caritemid, is there a way?
Sorry if I didn't explain it very well, I'm not the best of SQL queries.
解决方案
GROUP BY tblcaritem.caritemid
这篇关于SQL查询中没有重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!