MySQL-如何选择值在数组中的行? [英] MySQL - How to select rows where value is in array?

查看:59
本文介绍了MySQL-如何选择值在数组中的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,通常我知道,如果您知道数组值(在这种情况下为1,2,3),您会做类似的事情:

Ok, normally I know you would do something like this if you knew the array values (1,2,3 in this case):

SELECT * WHERE id IN (1,2,3)

但是我不知道数组的值,我只知道我要查找的值是存储"在数组中的:

But I don't know the array value, I just know the value I want to find is 'stored' in the array:

SELECT * WHERE 3 IN (ids) // Where 'ids' is an array of values 1,2,3

这不起作用.还有另一种方法吗?

Which doesn't work. Is there another way to do this?

推荐答案

使用 FIND_IN_SET函数:

SELECT t.*
  FROM YOUR_TABLE t
 WHERE FIND_IN_SET(3, t.ids) > 0

这篇关于MySQL-如何选择值在数组中的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆