pid fid
6 19
7 19
8 19
9 19
7 30
6 30
我有一個這樣的表。我想選擇重複行, 當我送19,30個IDS使用的IN
條款,如:mysql得到重複行使用哪裏
Select pid from tablename where fid IN (19,30);
我想這些結果
pid
7
6
是否有任何MySQL的語句來得到這些結果?
pid fid
6 19
7 19
8 19
9 19
7 30
6 30
我有一個這樣的表。我想選擇重複行, 當我送19,30個IDS使用的IN
條款,如:mysql得到重複行使用哪裏
Select pid from tablename where fid IN (19,30);
我想這些結果
pid
7
6
是否有任何MySQL的語句來得到這些結果?
使用distinct
Select distinct pid from tablename where fid IN (19,30);
或者找到重複
select pid from tablename group by fid having count(*)>1
SELECT pid
FROM tableName
WHERE fid IN (19,30)
GROUP BY pid
HAVING COUNT(*) = 2
如果唯一約束是不fid
每個pid
定義,那麼你需要有DISTINCT
內COUNT
SELECT pid
FROM tableName
WHERE fid IN (19,30)
GROUP BY pid
HAVING COUNT(DISTINCT fid) = 2
SELECT
pid
FROM tablename
where fid IN (19,30)
group by
pid
首先,你應該組PID的並計數,然後拿那些與多個occurence
SELECT pid, count(*) AS cnt
FROM tablename
WHERE fid IN (19,30)
GROUP BY pid
HAVING cnt > 1
爲什麼不是6 7 8 9? –