sql语句,想用模糊查询,但子查询的结果有多个如下表A                               表B NAME     PHONE                   NAME
----------------                  --------------------------------
 aa       333                      aa
 bb       444                      bb
 kk(cc)   555                      cc
 MM       666                      ll想查询出在表A里,  表B里面的名字不包含在表A里的名字的记录.
也就是查询结果 NAME  PHONE
-----------------
  MM   666的谢谢帮忙

解决方案 »

  1.   

    select A.NAME,A.PHONE from 表A A,表B B where A.NAME != B.NAME;
    自己想的,,不知对不对.
      

  2.   

    mysql> select * from a;
    +--------+-------+
    | NAME   | PHONE |
    +--------+-------+
    | aa     |   333 |
    | bb     |   444 |
    | kk(cc) |   555 |
    | MM     |   666 |
    +--------+-------+
    4 rows in set (0.00 sec)mysql> select * from b;
    +------+
    | NAME |
    +------+
    | aa   |
    | bb   |
    | cc   |
    | ll   |
    +------+
    4 rows in set (0.00 sec)mysql>
    mysql> select *
        -> from a
        -> where not exists (select 1 from b where INSTR(a.name,name)>0);
    +------+-------+
    | NAME | PHONE |
    +------+-------+
    | MM   |   666 |
    +------+-------+
    1 row in set (0.00 sec)mysql> select *
        -> from a
        -> where not exists (select 1 from b where a.name like concat('%',name,'%'))
        -> ;
    +------+-------+
    | NAME | PHONE |
    +------+-------+
    | MM   |   666 |
    +------+-------+
    1 row in set (0.00 sec)mysql>
      

  3.   

    select * from a where name not exists(select name from b where a.name = b.name);