MySQL WHERE IN() [英] MySQL WHERE IN ()

查看:87
本文介绍了MySQL WHERE IN()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询是:

SELECT * FROM table WHERE id IN (1,2,3,4);

我将其用于用户组,并且一个用户可以在多个组中.但是看来,当一条记录具有多个ID(例如1和3)时,mySQL不会返回该行.

I use it for usergroups and a user can be in more than one group. but it seems that when a record has multiple id like 1 and 3, mySQL does not return that row.

是否也有办法获得该行?

Is there any way to get that row too?

推荐答案

您的查询将转换为

SELECT * FROM table WHERE id='1' or id='2' or id='3' or id='4';

它只会返回与其匹配的结果.

It will only return the results that match it.

一种避免复杂性的解决方法是将数据类型更改为SET. 然后,您可以使用 FIND_IN_SET

One way of solving it avoiding the complexity would be, chaning the datatype to SET. Then you could use, FIND_IN_SET

SELECT * FROM table WHERE FIND_IN_SET('1', id);

这篇关于MySQL WHERE IN()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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