Table1
ID Name
L2 abc
L3 xyz
L4 pqr
L5 ghi
Table 2
ID code
L4 1
L3 2
L4 4
L2 3
L4 1
在上表中,我想输出我收到的所有带有名称和代码的 ID,但 ID L4 除外,它不应包含代码 4。
最佳答案
您可以使用 join 和 where 条件
select a.id,a.name, b.code
from table1 a left join table2 b on a.id=b.id
and exists (select 1 from table2 c where a.id=c.id and c.code<>4 )
关于mysql - 两个表之间的sql查询数据过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55968348/