选择两个表的两列之间的差异

z9ju0rcb  于 2021-06-24  发布在  Mysql
关注(0)|答案(4)|浏览(435)

我有两张table:
表aemoji symbols:id(autoincrement)name:varchar last\u name:varchar国籍:varchar
tablebemoji symbols:id(autoincrement)name:varchar last\u name:varcharfootball:team:瓦尔查尔
我想得到tablea.name和tablea.last\u name的组合,但它们在tableb中不存在。。。。我不知道怎么。。。我累了:(

lh80um4z

lh80um4z1#

这也会起作用:

SELECT a.name, a.last_name 
FROM TableA a
WHERE NOT EXISTS (SELECT * FROM TableB b WHERE b.name=a.name AND b.last_name = a.last_name)
z18hc3ub

z18hc3ub2#

一个简单的左连接就足够了。当您对name和last name进行左连接,并且b.name为null时,这意味着该记录在表a中,而不是在表b中。

SELECT A.NAME, A.LAST_NAME
 FROM TABLEA A
 LEFT JOIN TABLEB B
 ON A.NAME = B.NAME AND A.LAST_NAME=B.LAST_NAME
 WHERE B.NAME is null and B.LAST_NAME is null;
k5ifujac

k5ifujac3#

使用以下给定的查询来获得所需的结果:

Select TABLEA.NAME, TABLEA.LAST_NAME 
from TABLEA 
INNER JOIN TABLEB 
ON TABLEA.NAME!=TABLEB.NAME AND TABLEA.LAST_NAME!=TABLEB.LAST_NAME;
q43xntqr

q43xntqr4#

试试这个:

select 
   concat(first_name, ' ', last_name) as full_name 
from TableA 
having full_name not in (
   select 
      concat(first_name, ' ', last_name) as full_name 
   from TableB
);

相关问题