2011-05-11 38 views
1

MySQL的全內加入

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。我如何編寫連接來執行此操作?

+2

,問題是......? – mingos

+0

編輯並添加了問題 – Michael

回答

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 
) 
+3

MySQL不支持完整的外連接。你需要一個左連接和右連接的聯合才能與MySQL一起工作。 – mingos