我有表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

解决方案 »

  1.   

    select * from a
    union
    select * from b
      

  2.   

    select * from a
    union
    select * from b 不行啊
    --+-------+
    | id | value |
    +----+-------+
    | 1  | A     |
    | 4  | B     |
    | 2  | A     |
    | 6  | B     |
    | 1  | B     |
    | 5  | B     |
    | 3  | A     |    id 1 有两个
      

  3.   

    select * from a
    union
    select * from b where id not in (select id from a)
      

  4.   

    select 
    *
    from (
    select * from a
    union
    select * from b where id not in (select id from a)
    ) aa 
    order by id asc