我有两个表:TITLE和BACKGROUND
后台有一个外键进入TITLE所以我正在尝试编写一个查询,它将返回任何具有多个匹配BACKGROUND的TITLE行。
SELECT T.ID
FROM TITLE T, BACKGROUND B
WHERE T.ID = B.TITLE_ID
AND /* there are multiple matching background rows */
答案 0 :(得分:3)
select t.id
from title t
where exists (select *
from background b
where b.title_id = t.id
having count(*) > 1 )
答案 1 :(得分:1)
你试过.....
select T.ID from (
SELECT T.ID,B.TITLE_ID, count(*)
FROM TITLE T, BACKGROUND B
WHERE T.ID = B.TITLE_ID
group by T.ID,B.TITLE_ID
having count(*) > 1
)