2013-03-21 93 views
0

我有兩個查詢導致兩個結果集需要比較兩個結果集並需要顯示它們之間的差異。希望我會得到很好的支持。謝謝。這些是我的查詢獲取兩個查詢之間的數據差異

查詢:1個

SELECT distinct c.sid_ident,c.fix_ident from corept.std_sid_leg as c INNER JOIN (SELECT sid_ident, transition_ident, max(sequence_num) seq, route_type FROM corept.std_sid_leg WHERE data_supplier='J' AND airport_ident='KBOS' GROUP BY sid_ident,transition_ident) b ON c.sequence_num=b.seq and c.sid_ident = b.sid_ident and c.transition_ident =b.transition_ident WHERE c.data_supplier='J' and c.airport_ident='KBOS'; 

查詢:2

SELECT name,trans FROM skyplan_deploy.deploy_sids ON d.name=c.sid_ident WHERE apt = 'KBOS' AND name != trans; 

比較是必須要做的上字段在skplan_deplay.deploy_sids corept.std_sid_leg和名稱sid_ident。由於Mysql不支持完整的外連接,所以我想使用左連接和右連接並結合兩個結果。但是我堅持這樣做。請幫助。我在使用左右連接時出現語法錯誤。謝謝。

+0

我提供的語法使用LEFT JOIN以及右join..so,我可以既工會結果 – user2037445 2013-03-21 09:05:02

+0

使用搜索功能始終是一個良好的開端,以上述兩種查詢組合。把你的查詢放入子查詢並閱讀:http://stackoverflow.com/questions/4796872/full-outer-join-in-mysql – fancyPants 2013-03-21 09:45:38

回答

1

以下查詢應模擬MySQL中的FULL OUTER JOIN

SELECT * 
FROM A 
LEFT OUTER JOIN B 
    ON A.NAME = B.NAME 
WHERE B.ID IS NULL 
    UNION ALL 
SELECT * 
FROM B 
LEFT OUTER JOIN A 
    ON B.NAME = A.NAME 
WHERE A.ID IS NULL; 

Compare the results of the with an actual FULL OUTER JOIN in SQL Server and you'll see it works.

+0

a.id的意義是什麼? – user2037445 2013-03-21 10:06:12

+0

非常感謝你..我一直堅持這個3小時以上..只是通過放置這是空條款我解決了這個問題。真的比thanx很多 – user2037445 2013-03-21 10:07:45

+0

看看[這個鏈接](http:// www .codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html)查看普通'FULL OUTER JOIN'和返回差異的區別。 – JodyT 2013-03-21 10:37:16