我有表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
uj5u.com熱心網友回復:
select * from aunion
select * from b
uj5u.com熱心網友回復:
select * from aunion
select * from b
不行啊
--+-------+
| id | value |
+----+-------+
| 1 | A |
| 4 | B |
| 2 | A |
| 6 | B |
| 1 | B |
| 5 | B |
| 3 | A | id 1 有兩個
uj5u.com熱心網友回復:
select * from aunion
select * from b where id not in (select id from a)
uj5u.com熱心網友回復:
結帖率:0%uj5u.com熱心網友回復:
select*
from (
select * from a
union
select * from b where id not in (select id from a)
) aa
order by id asc
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/115325.html
標籤:MySQL
