S
S
sevic2020-02-16 16:01:28
MySQL
sevic, 2020-02-16 16:01:28

How to get data from 2 different tables and with different fields?

for example 2 tables
t1 (id_user, user_name)
t2 (id_article, description, content,)
UINION ALL does not work - different number of columns.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2020-02-16
Tag

you need to equalize the number of fields in the selections, for example

SELECT t1. id_user, t1.user_name, NULL
FROM t1
UNION ALL
t2.id_article, t2.description, t2.content
FROM t2

some engines may require explicit casting in this case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question