Answer the question
In order to leave comments, you need to log in
How to select the required fields from the database depending on the result of a LEFT JOIN?
Conditional request example:
SELECT IFNULL(t1.first_name, t2.username) as first_name,
IFNULL(t1.last_name, t2.domain) as last_name
FROM user u
LEFT JOIN table1 t1 ON t1.user_id = u.id AND user.type = 1
LEFT JOIN table2 t2 ON t2.user_id = u.id AND user.type = 2
Answer the question
In order to leave comments, you need to log in
The request is correct, exactly like this (with IFNULL) and it should be.
And that it was not necessary so to be perverted - normalize tables.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question