'How to select from two identical table?

So I have a table but partitioned by month, for example

table_202201, table_202202

I would like to select from two tables, how can I do that?

select * from table_202201, table_202202

What I want is, for example,

Say table_202201:

id name date
1. a.   20220101
2. b.   20220101

table_202202:

id name date
11. aa.   20220201
22. bb.   20220201

I would like to get results like this:

id name date
1. a.   20220101
2. b.   20220101
11. aa.   20220201
22. bb.   20220201


Solution 1:[1]

If I understand correctly, you can try to use UNION ALL instead of , (CROSS JOIN)

SELECT * FROM table_202201
UNION ALL
SELECT * FROM table_202202

I would use explicitly specify columns which you want to select instead *

SELECT id,name,date
FROM (
    SELECT id,name,date FROM table_202201
    UNION ALL
    SELECT id,name,date FROM table_202202
) t1
ORDER BY id

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1