Answer the question
In order to leave comments, you need to log in
How to get data from two mysql tables?
There are 2 tables
Connects their column "num" It is
necessary to select all "name" from table_2, and if there is null in the "name" field, then it climbs into table_1 and takes the value from there.
As a result, the result of the selection is as follows:
What will the request look like in one line?
In general, it will be even cooler if in the form of activeQuery yii2 =)
Answer the question
In order to leave comments, you need to log in
SELECT ID, Num, Name FROM Table_1
UNION
SELECT ID, Num, Name FROM Table_2 WHERE NOT Name IS NULL
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question