一共有三个表
table a
table b
table c
我的查询是:
select a.title,a.id,b.title
from table a
case when a.type=1 then
inner join table a.id=tableb.id end
case when a.type=2 then inner join table a.id=table c.id
但是这个查询不起作用。有人可以帮助提供正确的方法来获取或执行此类查询
最佳答案
不能在 from 子句中使用 case。为了实现这一点,您可以使用 UNION ALL。例如:
select a.title,a.id,b.title
from table a inner join table b on a.id=b.id
where a.type=1
UNION ALL
select a.title,a.id,c.title
from table a inner join table c on a.id=c.id
where a.type=2
关于mysql连接三个表的case语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23054449/