表A
CODE    NANEM ..................
1234    fdfdfd..................
2345    ........................表B
CODE    ........................
1234    ........................
5555    ........................我想要的结果就是 表A和表B CODE列的合集
:
结果为:
CODE    .........................
1234    ......................... 
2345    .........................
5555    .........................在线等

解决方案 »

  1.   

    select * from A
    union all
    select * from B
      

  2.   

    我想要的结果就是 表A和表B CODE列的合集:
    两表中有相同CODE的,NAME以哪个表为准?B表?
      

  3.   

    mysql> select * from a;
    +------+--------------------------+
    | code | namem                    |
    +------+--------------------------+
    | 1234 | fdfdfd.................. |
    | 2345 | ........................ |
    +------+--------------------------+
    2 rows in set (0.00 sec)mysql> select * from b;
    +------+--------------------------+
    | code | namem                    |
    +------+--------------------------+
    | 1234 | ........................ |
    | 5555 | ........................ |
    +------+--------------------------+
    2 rows in set (0.00 sec)mysql>
    mysql> select * from a where code not in (select code from b)
        -> union
        -> select * from b
        -> order by code;
    +------+--------------------------+
    | code | namem                    |
    +------+--------------------------+
    | 1234 | ........................ |
    | 2345 | ........................ |
    | 5555 | ........................ |
    +------+--------------------------+
    3 rows in set (0.00 sec)mysql>