SQL如何比较两个表中的数据并获得两个表之间不同的结果 [英] SQL How to compare data in two tables and get the results that are different between two tables

查看:642
本文介绍了SQL如何比较两个表中的数据并获得两个表之间不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有2张桌子.表a和b. A包含msisdn,firstname,secondname,lastname,regdate(注册数据).表b也具有相同的字段.我想比较这两个表,即msisdn的firstname和lastname字段.如果表A中的msisdn X的名字为jim,姓氏为halpert,而同一表中的msisdn X的名字为michael,第二名为scott,则我需要获取这些类型的msisdn作为我的查询结果.在两个表中具有相同msisdn且名称不同的人.如果这些名称(名字或姓氏)不匹配,则应将其显示为结果.

There are 2 tables. Table a and b. A contains msisdn, firstname, secondname, lastname, regdate(registration data). Table b also has the same fields. I want to compare these two tables, the msisdn's, firstname and lastname fields. If msisdn X in table A has firstname as jim and lastname as halpert, and the same msisdn X has firstname as michael and secondname as scott in table B, i need to get these kinds of msisdn's as my query result. the one's with same msisdn in both tables and different names. if either of these names(first or last) mismatches, that should be shown as result.

对不起,如果我没有正确解释这种情况.我希望有人能理解并回答这个问题.

I'm sorry if i did not explain the scenario accurately. I hope someone understands and answers this.

感谢:)

推荐答案

SELECT A.*, B.* 
FROM TABLEA A
INNER JOIN TABLEB B ON A.MSISDN = B.MSIDN
WHERE A.firstname != B.firstname 
OR A.lastname != B.Lastname

这篇关于SQL如何比较两个表中的数据并获得两个表之间不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆