doufei1852 2014-04-18 05:11
浏览 1300
已采纳

PHP / MYSQL-如何使用IN查询

When i am add new post that time select multiple category and store in database like 48,52 into single field sub_cat_id

I am try to get value using IN but not get properly

SELECT *
FROM tbl_listing 
WHERE status='1' and sub_cat_id IN (52)
ORDER BY tbl_listing.company_name DESC LIMIT 0, 15

enter image description here

I am store value into db like below screenshot

Please help me

  • 写回答

3条回答 默认 最新

  • doublel83422 2014-04-18 05:45
    关注

    If you are passing 48,52 as comma separated numbers as a string to IN then search is not performed correctly. You have to use FIND_IN_SET with column and the CSV value.

    SELECT * FROM tbl_listing 
    WHERE status='1' 
      and ( FIND_INSET( 48, sub_cat_id ) > 0
            OR FIND_INSET( 52, sub_cat_id ) > 0 )
    ORDER BY 
      tbl_listing.company_name DESC 
    LIMIT 0, 15
    

    Refer to:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器