Question : MySql Conditional from

Hi

I would like to have a conditional FROM statement
Depending on the value of a certain field a join must be used or not

I tried following, but this gives an error

SELECT DISTINCT rubriek.*
FROM
CASE
WHEN LENGTH(rubriek.override_ext) = 0 THEN
(publish INNER JOIN rubriek ON publish.rubriek_id = rubriek.rubriek_id)
INNER JOIN actie ON publish.actie_id = actie.actie_id
ELSE rubriek
END CASE
WHERE
rubriek.visible = 1
CASE
WHEN LENGTH(rubriek.override_ext) = 0 THEN
AND publish.rubriek_id > 1
END CASE

Answer : MySql Conditional from

SELECT DISTINCT rubriek.*
FROM rubriek
LEFT JOIN publish ON publish.rubriek_id = rubriek.rubriek_id
   AND LENGTH(rubriek.override_ext) = 0
LEFT JOIN actie ON publish.actie_id = actie.actie_id
   AND LENGTH(rubriek.override_ext) = 0
WHERE rubriek.visible = 1
   AND ((LENGTH(rubriek.override_ext) <> 0) OR (publish.rubriek_id > 1 AND actie.actie_id is not null))
Random Solutions  
 
programming4us programming4us