mysql 中有什么关键字可以代替 sql语言中的 in ?

解决方案 »

  1.   

    not existmysql> select * from foo where id in (3);
    +------+------+
    | id   | col2 |
    +------+------+
    |    3 | 美国 |
    |    3 | 美国 |
    |    3 | 美国 |
    |    3 | 美国 |
    |    3 | 美国 |
    |    3 | 美国 |
    +------+------+
    6 rows in set (0.02 sec)mysql> select * from foo a where not exists (select id from foo b  where a.id = b.id and b.id != 3);
    +------+------+
    | id   | col2 |
    +------+------+
    |    3 | 美国 |
    |    3 | 美国 |
    |    3 | 美国 |
    |    3 | 美国 |
    |    3 | 美国 |
    |    3 | 美国 |
    +------+------+
    7 rows in set (0.00 sec)
      

  2.   

    find_in_set()mysql> SELECT FIND_IN_SET('b','a,b,c,d');
            -> 2
      

  3.   

    具体是什么?字符、数字?查询表中记录是否匹配?
    INSTR、FIND_IN_SET、LEFT JOIN?
      

  4.   

    select s.* from cdb_posts s where s.tid in (select distinct cdb_posts.tid from cdb_posts ORDER by dateline desc limit 5)
    是这样的 我需要查询出discuz最近时间有过动态的帖子,以前用的是
    select distinct cdb_posts.tid from cdb_posts ORDER by dateline desc limit 5 但是后来在论坛中做测试,在查询的数据中 “subject” 变成了空的,经过分析发现这些“subject”为空的数据,tid 列值都是一样,所以改变了sql 这种思想是对的 不过执行不成功 ,说 in 和 limit 不能同时使用。
      

  5.   

    select s.* from cdb_posts s 
    inner join (select distinct cdb_posts.tid from cdb_posts ORDER by dateline desc limit 5) b
    on s.tid=b.tid
      

  6.   

    or
    select s.* from cdb_posts s ,(select distinct cdb_posts.tid from cdb_posts ORDER by dateline desc limit 5) b
    where s.tid=b.tid 
      

  7.   

    这个就多了,上面说的EXSITS, FIND_IN_SET,LEFT JOIN,甚至普通的JOIN都可以,具体看需求了