我有表,其中类型A有两个值,类型B有两个值
A | B
-----|--------
val1 | val1
val2 | val2
我做子查询,但我得到了dubolicate值,看起来像这样
A | B
-----|--------
val1 | val1
val1 | val2
val2 | val1
val2 | val2
我的查询:
SELECT A, B
FROM
(SELECT DISTINCT title as A
FROM TABLE1
INNER JOIN TABLE2 ON TABLE1_TABLE2_ID = TABLE2_ID
INNER JOIN TABLE3 ON TABLE1_TABLE3_ID = TABLE3_ID
WHERE TABLE_TABLE3_ID = 2008 AND TABLE_TYP LIKE 'A' AND TABLE1_AKTIV = 'Y')
LEFT JOIN
(SELECT DISTINCT title as B
FROM TABLE1
INNER JOIN TABLE2 ON TABLE1_TABLE2_ID = TABLE2_ID
INNER JOIN TABLE3 ON TABLE1_TABLE3_ID = TABLE3_ID
WHERE TABLE_TABLE3_ID = 2008 AND TABLE_TYP LIKE 'B' AND TABLE1_AKTIV = 'Y')
ON 1 = 1
你有什么想法我怎么能做到没有重复?
答案 0 :(得分:1)
问题是ON 1=1
。这将为您提供所有组合。您需要使用适当的参考列更改查询,例如ON A.id=B.id
。