2012-06-01 52 views
0

“表1” ---> boodang_iphone包含--- 3000条记录获取不匹配值加入SQL两个表

“表2” - > boodang_iphonePushtest05302012表包含---共有90条记录

我需要获得“boodang_iphonePushtest05302012”偏差值比较表1我写这样

SELECT boodang_iphonePushtest05302012.devicetoken 
FROM boodang_iphonePushtest05302012 
left outer join boodang_iphone on 
    boodang_iphone.devicetoken=boodang_iphonePushtest05302012.devicetoken 
where 
    boodang_iphonePushtest05302012.devicetoken != boodang_iphone.devicetoken 

我很困惑查询是它给正确的数据或不属于任何一个我们可以请指导我用得到偏差值加入

回答

1

此查询为您提供boodang_iphonePushtest05302012中存在的所有记录,但不包含在boodang_iphone中。但是,您需要再次通过交换表来运行查询,因此它会为您提供boodang_iphone中的所有记录,但不包含在boodang_iphonePushtest05302012中(您可以使用相同的查询,但通过右外部连接加入表)。那么你应该得到比较的全部结果。

此外,如果你可以改变你的where子句

where boodang_iphone.devicetoken IS NULL 

然后会好得多。这是因为如果值不匹配,那么它将从第二个表中返回NULL值,并且如果将NULL值与有效数据进行比较,它总是有问题。