2016-05-03 10:45
浏览 450


SQL in 'services' column I have an arrays values like e.g.: 2,19,72,5,46,45,38,40,36,27,29

For selecting this row from DB I'm using this query:

SELECT * FROM myTable WHERE `services` IN (2,19)

And it is working OK. But, when I do changes in 'IN' closure like below:

SELECT * FROM myTable WHERE `services` IN (19)

it always returns 0 rows. The query is searching only for the first value in column. Why this is happening and how can I change my query to work it correctly?

Thanks in advance.

图片转代码服务由CSDN问答提供 功能建议

'services'列中的SQL我有一个数组值,例如:2,19,72,5,46, 45,38,40,36,27,29


  SELECT  * FROM myTable WHERE`services`IN(2,19)

它工作正常。 但是,当我在'IN'闭包中进行更改时,如下所示:

  SELECT * FROM myTable WHERE`services`IN(19)

它总是返回0行。 该查询仅搜索列中的第一个值。 为什么会发生这种情况?如何更改查询以使其正常工作?


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • dongtao1262 2016-05-04 10:58

    Update your query like : If you search only single value...

    SELECT * FROM myTable WHERE concat(',',`services`,',') like '%19%'

    But if you want to search 19,2 or 2,40 or 40,19 it will not work. for that case you need to write query dynamically

    解决 无用
    打赏 举报

相关推荐 更多相似问题