strid字段中存266,269,272,273内容。如果传一个ID为272查询 where strid in (272)
没有得到结果。。请问我的写法对吗

解决方案 »

  1.   

    为什么要用in呢?where strid=272 多好啊
      

  2.   

    select * from tables1 where id in(select id from tables2 )
      

  3.   

    上面的都测试了。。没有结果出来。strid内容是266,269,272,273。是多个的方式存放的,传266或272才找有这记录的出来
      

  4.   


    mysql> select * from a;
    +----------------+
    | id             |
    +----------------+
    | 123,234,543,45 |
    | 12,65,34,6,4   |
    | 23,23,65,34,54 |
    +----------------+
    3 rows in set (0.00 sec)mysql>  select * from a where 123 in (id);
    +----------------+
    | id             |
    +----------------+
    | 123,234,543,45 |
    +----------------+
    1 row in set (0.00 sec)
      

  5.   

    where strid like '%272%'
      

  6.   

    楼主你看看字段的类型试试
    where strid in ('272') 
      

  7.   

      你 的 类型对不啊 
    下面是我刚从数据中写的一条语句:SELECT * FROM petinfo WHERE pet_id IN (6)我的pet_id为int  在数据库这样查是对的
      

  8.   

    我类型是varchra的 如果是int的类型。。加不了,号啊
      

  9.   

    show create table table_name;  看一下你的表结构
      

  10.   

    `id` int(11) NOT NULL auto_increment,
    `strid` varchar(200) default NULL,是这样子的
      

  11.   

    是varchar的应该就可以查询得出来啊
      

  12.   

    mysql> select * from cg where 272 in (strid);
    Empty set
    我查询结果是这样的
      

  13.   

    zho 你试试找下234。应该没有的。我找第一位266,269,272,273的266也有数据。但是找272就没有了
      

  14.   

    嗯!是查询不出来,你试一下这条语句:mysql> select * from a;
    +----------------+
    | id             |
    +----------------+
    | 123,234,543,45 |
    | 12,65,34,6,4   |
    | 23,23,65,34,54 |
    | 432,76        |
    +----------------+
    4 rows in set (0.02 sec)mysql> select * from a where find_in_set(234,id);
    +----------------+
    | id             |
    +----------------+
    | 123,234,543,45 |
    +----------------+
    1 row in set (0.00 sec)