我有表A 格式如下
| id | value |
| 1 | A |
| 2 | A |
| 3 | A |
表B
id | value |
| 5 | B |
| 6 | B |
| 4 | B |
| 1 | B |
表A与B连接 怎样写sql才能形成如下表结构
id value
1 A
2 A
3 A
4 B
5 B
6 B
我有表A 格式如下
| id | value |
| 1 | A |
| 2 | A |
| 3 | A |
表B
id | value |
| 5 | B |
| 6 | B |
| 4 | B |
| 1 | B |
表A与B连接 怎样写sql才能形成如下表结构
id value
1 A
2 A
3 A
4 B
5 B
6 B
不考虑性能的笨方法
select * from B where id not in (select id from A) 是要排除 B中与A的id相同的记录
select * from (
(select * from A) union all
(select * from B where id not in (select id from A))
) c order by c.id asc