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 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 已知隐函数其中一个变量的,求另外一个变量
  • ¥15 echarts图表制作
  • ¥15 halcon根据玻璃面板纹路取区域
  • ¥15 HFSS设计小型化180度耦合器
  • ¥15 使用CInternetSession,CHttpFile读取网页文件时有些电脑上会卡住怎么办?
  • ¥15 水下机器人的半物理仿真研究
  • ¥15 微服务假死,一段时间后自动恢复,如何排查处理
  • ¥50 webrtc-streamer TCP rtsp