获取两个查询之间的数据差异

时间:2013-03-21 09:00:15

标签: mysql

我有两个查询导致两个结果集我需要比较两个结果集并需要显示它们之间的差异。希望我会得到很好的支持。谢谢。这些是我的疑问

查询: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;

要对corept.std_sid_leg中的字段sid_ident和skplan_deplay.deploy_sids中的名称进行比较。由于Mysql不支持完全外连接,我想到使用左连接和右连接并结合两个结果。但我坚持这个。请帮助。我在使用左右连接时出现语法错误。谢谢。< / p>

1 个答案:

答案 0 :(得分: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.