MYSQL比较LEFT JOIN中的多个值

时间:2013-10-11 07:38:29

标签: mysql left-join

如何比较左连接中的多个值?

我有两张桌子

table a
id val
1   a
2   b
3   c
4   a

table b
val fullform
a    apple
b    banana
c    cat

我会写,

select a.id, b.fullform from a left join b on a.val=b.val

我假设它将加入a = a或b = b

我想这样比较,

select a.id, b.fullform from a left join b on a.val in (a,b)

是否可以不在WHERE中写出来。

1 个答案:

答案 0 :(得分:0)

你很亲密:

select a.id, b.fullform from a left join b on a.val = b.val
where a.val in (a,b)