检查两个表记录的SQL查询是否匹配 [英] Sql query for check two tables record is matched or not

查看:113
本文介绍了检查两个表记录的SQL查询是否匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想要sql查询比较两个tabled。添加一列。列名是状态。如果匹配状态匹配。否则无法比拟。

Hi,
I want sql query for compare two tabled. Add one column. Column name is status. If it is matched status is matched. Otherwise unmatched.

推荐答案

你必须使用FULL OUTER JOIN

这里是查询



You have to user FULL OUTER JOIN
here is the query

SELECT table1.id, 
CASE WHEN table2.sal IS NULL then 'unmatched'
ELSE 'matched' END  AS status,
table1.name,table1.address
 FROM table1 FULL OUTER JOIN table2 ON TABLE1.id = tables2.id 





如果有帮助,请将其标记为答案。



please mark it as answer if it helps.


检查您的表结构是否正确。我没有理由在表2中获得薪水。无论如何,你可以从这里开始[ ^ ]
Check your table structure if it's right. I don't see a reason to have salary in table2. Anyway, You can get a start from here[^]


这篇关于检查两个表记录的SQL查询是否匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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