LEFT JOIN时的情况?

时间:2018-03-20 13:47:59

标签: mysql symfony dql

我想根据其他表中的值选择左连接表。 所以我尝试了这个,但没有工作:

CASE WHEN c.catId LIKE "%s%" THEN 
  LEFT JOIN AppBundle:newspaper_subcategories cat WITH c.catIdShort = cat.id
ELSE 
  LEFT JOIN AppBundle:newspaper_categories cat WITH c.catIdShort = cat.id
END

1 个答案:

答案 0 :(得分:0)

只需左键加入两个表,但在列子句

上使用CASE语句
SELECT 
  . . . 
 CASE WHEN c.catId LIKE '%s%' 
 THEN sub.somecolumn
 ELSE cat.somecolumn
 END
  . . . 
LEFT JOIN AppBundle:newspaper_subcategories sub ON c.catIdShort = cat.id
LEFT JOIN AppBundle:newspaper_categories cat ON c.catIdShort = cat.id