Hello, could anyone help me to reconstruct the bellow query? (please notice it’s only a part of a bigger query). I’d like to return “0” when banner has value 0, and use Join for other cases.
SELECT core.name AS author, core.layout, core.banner, core.ad AS ads
FROM (
SELECT al.name, ll.name AS layout, p.banner, CASE p.banner WHEN 0 THEN "0" ELSE (JOIN media AS m ON p.banner = m.file_name) END AS ad
FROM posts AS p
JOIN authors_look AS al USING(author_id)
JOIN layouts_look AS ll USING(layout_id)) AS core
Exactly, this is the part I’m talking about. By using CASE (or IF) I’d like to return any result, now (when banner = 0) I get empty result. It should be:
author layout banner ads
Tom long 0 “0”
Jane short 33 “bird.jpg”
Lisa long 103 “flower.jpg”