【发布时间】:2021-05-22 17:42:32
【问题描述】:
我有两张桌子
table_1
| number | type | name |
|---|---|---|
| 12 | 1 | steve |
| 12 | 2 | smith |
| 12 | 2 | jack |
等等……
类似
table_2
| number | type | name |
|---|---|---|
| 12 | 1 | abraham |
| 12 | 2 | jack |
| 12 | 2 | smith |
这里我正在做内部连接,当数字和类型相等时,我需要输出名称不匹配的地方。我的查询是
select * from table1,table2
where table1.number=table2.number and table1.type=table2.type and table1.name <> table2.name
预期输出:
| number | type | name |
|---|---|---|
| 12 | 1 | abraham |
而不是来自类型'2'
但输出显示类型为“2”的 smith jack 和 jack smith,因为在两个表中都有名为 jack,smith 的数据为类型 2。预期的输出仅适用于类型“1”,因为有mismatch 谁能帮帮我?
【问题讨论】:
标签: mysql sql join left-join inner-join