转自https://juejin.cn/post/7148305978922893349
MySQL的in语法,相信大家用的最多的就是下面的语句了:
SELECT * FROM test
WHERE id IN (1, 2, 3)
但是in关键字他是支持多个字段的,比如下面写法:
SELECT
*
FROM
`test`
WHERE
(id_type,id_number) IN ((1,'12345'),(2,'67890'))
上面的语句相当于下面写法:
SELECT
*
FROM
`test`
WHERE
(id_type = 1 AND id_number = '12345')
OR
(id_type = 2 AND id_number = '67890');
本文作者使用MySQL版本5.6,MySQL8上也适用