我有
SELECT clientReport.id
FROM clientReport
LEFT JOIN report02 ON (report02.id = clientReport.id)
WHERE report02.id is null;
相当于
SELECT clientReport.id
WHERE clientReport.rowNumber NOT EXISTS (
SELECT clientReport.rowNumber FROM report02, clientReport
WHERE report02.id=clientReport.id);
我可能需要一个完整的内部联接来获取report02中的不匹配,而不仅仅是clientReport。如何编写联接来执行此操作?
答案 0 :(得分:1)
以下内容应该有效。
SELECT clientReport.id,report02.id
FROM clientReport
FULL OUTER JOIN report02 ON (report02.id = clientReport.id)
WHERE report02.id is null
OR clientReport.id is null;
应该但它没有(因为MySQL目前不支持FULL OUTER JOIN
。)
这更有可能奏效:
( SELECT clientReport.id AS report01
, report02.id AS report02
FROM clientReport
LEFT OUTER JOIN report02
ON (report02.id = clientReport.id)
WHERE report02.id IS NULL
)
UNION
( SELECT clientReport.id AS report01
, report02.id AS report02
FROM clientReport
RIGHT OUTER JOIN report02
ON (report02.id = clientReport.id)
WHERE clientReport.id is null
)