A
A
Alexander Verbitsky2019-02-14 06:59:33
Yii
Alexander Verbitsky, 2019-02-14 06:59:33

How to get data from two mysql tables?

There are 2 tables
5c64e60abb49b754102954.png
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:
5c64e738b7376605500472.png
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

1 answer(s)
K
Konstantin Tsvetkov, 2019-02-14
@VerbAlexVlad

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 question

Ask a Question

731 491 924 answers to any question