我有这个查询
SELECT *
FROM GUITARS.FENDER
WHERE FENDER.GUITARTYPE IN (
SELECT GUITARTYPE,GUITARSUBTYPE
FROM GUITARS.GUITAR_TYPE
WHERE GuitarColor = 'RED')
当我只在子查询中执行GUITARTYPE而不是GUITARTYPE,GUITARSUBTYPE时,我可以运行它。
答案 0 :(得分:2)
请勿使用in
,请使用exists
:
SELECT *
FROM GUITARS.FENDER
WHERE EXISTS (SELECT 1
FROM GUITARS.GUITAR_TYPE
WHERE GuitarColor = 'RED' AND
FENDER.GUITARTYPE = GUITARTYPE.GUITARTYPE AND
FENDER.GUITARSUBTYPE = GUITARTYPE.GUITARSUBTYPE
);