2013-03-21 57 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