Return data from two identical tables [SQL] [Python]

Asked

Viewed 280 times

-1

Hi, I want a help with SQL query.

There are two identical tables but with different recorded data in each one. How can I get the data from both tables? As if they were two selects in each table?

Type: select * tabela1,select * tabela2

But I would like the return to be only one.. For now without any condition/comparison, just return all data from both tables.

I’m programming in python, can I do that in programming? I believe so but I think it would be slower, right?

  • If I can understand the desired result try UNION: select * tabela1 UNION select * tabela2. Perhaps, depending on the desired result, it is necessary UNION ALL

1 answer

1

You can use FULL OUTER JOIN:

SELECT 
TABELA1.*, 
TABELA2.* 
FROM TABELA1
FULL OUTER JOIN TABELA1 ON TABELA1.Chave = TABELA2.Chave

You can use UNION ALL:

SELECT * FROM TABELA1
UNION ALL
SELECT * FROM TABELA2

in which case the return of each query will be under the other, if you want side by side, you would have to do a sub-select with max, which I believe is not worth, it will be better to use the full Outer Join and filter what you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.