如何从包含数据组合的列中获取结果?

时间:2009-06-30 03:18:20

标签: sql mysql

数据:

id  bb
1  14,35
2  5,11,12,125,36
3  3,23,45,15,1
4  651
5  5,1,6
6  1,7

例如,我不会得到值为'1'的id。所以id(3,5,6)应该返回,而不是'14'或'11'的其他人。

DB:Mysql

4 个答案:

答案 0 :(得分:2)

这不是最有效的解决方案,但它可能会为您提供您想要的内容:

select id from MyTable where bb like '%,1,%' union 

select id from MyTable where bb like '1,%' union 

select id from MyTable where bb like '%,1' union 

select id from MyTable where bb like '1'

欢呼声

答案 1 :(得分:1)

select * from test where find_in_set('1',bbb)

select * from test where bbb REGEXP '(^|,)1(,|$)'

答案 2 :(得分:0)

我错过了什么吗?

SELECT *
FROM   MyTable
WHERE  (id = 3) or (id = 5) or (id = 6)

答案 3 :(得分:-1)

你可以这样做 select * from mytable,其中id为'14%'或'11%'