mysql in 数组_MySQL IN()有两个值/数组吗?

bd96500e110b49cbb3cd949968f18be7.png

I'm having trouble finding a better way to search MySQL for a pair of values in a table. I have the value pairs in an array, and would like to duplicate the IN() function, but for more than 1 value.

For example purposed; I have the following 3 pairs:

foo,1

boo,2

goo,3

The current solution puts me at:

SELECT * FROM [table] WHERE

(column1 = 'foo' AND column2 = 1) OR

(column1 = 'boo' AND column2 = 2) OR

(column1 = 'goo' AND column2 = 3);

I'd like to think there's a more "sexy" solution seeing that I could have as many as a hundred pairs and having that may ORs kind of makes me nauseous. Thanks!!!

解决方案SELECT *

FROM foo

WHERE (column1, column2) IN (('foo', 1), ('bar', 2))

This syntax may be confusing, and it may be more readable to replace it with:

SELECT *

FROM foo

WHERE ROW(column1, column2) IN (ROW('foo', 1), ROW('bar', 2))

I'm used to the former one, though :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值