Sophairk Chhoiy
Sophairk Chhoiy

Reputation: 17

MySQL: How to select multiple tables (No join) ? (See example)

How to select multiple table (combine table: no join, because all field are the same)?

I have 2 tables: +Table A

id | name | description | time
1     A        AA          7:01
2     B        BB          7:03

+Table B

id | name | description | time
1     C        CC          7:02
2     D        DD          7:04

I want to result:

Result: (ORDER BY time)

id | name | description | time
1     A        AA          7:01
1     C        CC          7:02
2     B        BB          7:03
2     D        DD          7:04

Upvotes: 0

Views: 52

Answers (2)

Stefano Zanini
Stefano Zanini

Reputation: 5916

You can use UNION ALL

select  *
from    (
            select * from TableA
            union all
            select * from TableB
        ) t1
order by time

If you can have duplicates and want to avoid them, just switch from UNION ALL to UNION

Upvotes: 1

Jens
Jens

Reputation: 69440

use Union all

select id, name, description, time from tableA
Union all
select id, name, description, time from tableB
order by time

Upvotes: 1

Related Questions