MySQL WHERE IN ()

MySQL WHERE IN ()(MySQL WHERE IN ())
本文介绍了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 ()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)