豹纹:相同字段问题

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 05:25:12
一个数据库中的两个表:table1和table2,table1和table1中均有一个“XM”(姓名)字段,这两个表中的“XM”字段没有关联,但两个表中有很多条记录的“XM”相同。现在我想将两个表中XM不相同的记录的“XM”字段显示出来,用SQL应如何编写?
第一行中的后半句是“table1和table2中均有一个‘XM’”

(select 'table1',XM from table1 where not exists(select XM from table2 where XM=table1.XM))
union all
(select 'table2',XM from table2 where not XM in (select distinct XM from table1))