-1

I want to select the left join table depending on a value from other table. So I tried this, but not working:

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
M. F
  • 77
  • 9

1 Answers1

1

Simply left join the two tables but use the CASE statement on the column clauses

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
Stavr00
  • 3,219
  • 1
  • 16
  • 28