I have three tables : email, customer_new and customers_old.
Now in email table there is a field called type that contains 0 or 1.
So if type contains 0 then I want to fetch name column from customer_new table else from customer_old table.
For this I made below mysql query :
SELECT email.*,
CASE email.`type`
WHEN 1 THEN customer_old.name
ELSE customer_new.name
END AS customer_name
LEFT JOIN
CASE email.`type`
WHEN 0 THEN customer_new ON email.customer_id = customer_new.id
ELSE customer_old ON email.customer_id = customer_old.id
END
FROM email
Now when I run this query mysql always throws error.
Can somebody solve my issue regarding join two table through CASE statement based on condition ?
Thanks in advance.