次のような列を持つテーブルがあります。
serial_id season ep_id
1 1 1 < duplicate
1 1 2
3 1 1
...
1 1 1 < duplicate
serial_id、season、ep_idの値が重複しているすべての行を選択したいのですが、どのクエリを使用すればよいですか?ありがとう。
"..serial_id、season、ep_idの値が重複しています。"
SELECT serial_id, ep_id, season
FROM tableName
GROUP BY serial_id, ep_id, season
HAVING COUNT(*) > 1
ただし、行内のすべての列(* serial_id、ep_id、season以外の他の列があると仮定*)を取得する場合
SELECT a.*
FROM tableName a
INNER JOIN
(
SELECT serial_id, ep_id, season
FROM tableName
GROUP BY serial_id, ep_id, season
HAVING COUNT(*) > 1
) b ON a.serial_id = b.serial_id AND
a.ep_id = b.ep_id AND
a.season = b.season
このようなもの:
select serial_id, season, ep_id, count(*) records
from yourtable
group by serial_id, season, ep_id
having count(*) > 1