我正在尝试编写一个查询来查找在另一个表中没有匹配记录的记录。
这是我的设计表
table 1
id | fid | phone | name
1a | 1b | 201 | dave
1a | 2c | 012 | albert
1a | 2z | 909 | huerem
3a | 2f | 919 | merria
2a | 9z | 209 | gonma
table 2
id | phone
4x | 121
2c | 121
1d | 009
3b | 889
5a | 121
我想显示table2中phone=121的记录,table2.id
不存在在table1.fid
中,所以结果将为 4x,5a
有任何查询要执行此操作吗?
最佳答案
所以左连接表并指定 null
select t.*
from table2 t
left join table1 tt on t.id = tt.fid
where tt.fid is null and t.phone = 121
关于mysql - 显示表中不匹配的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33338083/