A
A
Alexander2018-12-15 22:33:33
SQL
Alexander, 2018-12-15 22:33:33

How to get data from multiple tables?

There are four different tables which are not connected with each other in any way (and it is not necessary).
How can one script of them get the data all in one heap? It's getting dark again and I can't figure it out :( It is
necessary to unload without repetitions) i.e. DISTINCT
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Hanneman, 2018-12-15
@barrty

I already answered here , but I will duplicate it again (and I remind you that there should be more details in the questions).
So:

select distinct your_value from (
    select your_value from table_1
    union
    select your_value from table_2
    union 
    select your_value from table_3
    union 
    select your_value from table_4
) x;

As for the question in general, is it possible to use one query from different tables, it looks like this (and there is nothing supernatural here):
select t1.name, t2.name
from table_1 t1, table_2 t2
where t1.id = t2.id;

K
Konstantin Tsvetkov, 2018-12-15
@tsklab

UNIONconnects different SELECTin one request without repeating the connected data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question