SQL IN
IN 允许在 WHERE 中指定多个候选值,等价于多个 OR;也可接子查询。
Key PointsSQL,IN,子查询,多值匹配
讲解
IN 允许在 WHERE 中指定多个候选值,等价于多个 OR;也可接子查询。
示例
SQL
SELECT * FROM Websites
WHERE country IN ('CN', 'US');Output
id name url alexa country
-- --------- ------------------------- ----- -------
1 Google https://www.google.com/ 1 US
2 淘宝 https://www.taobao.com/ 13 CN
3 菜鸟教程 https://www.runoob.com/ 4689 CN
4 微博 https://weibo.com/ 20 CN
5 Facebook https://www.facebook.com/ 3 US讲解
IN 允许在 WHERE 中指定多个候选值,等价于多个 OR;也可接子查询。
示例
SQL
SELECT * FROM Websites
WHERE country IN ('CN', 'US');Output
id name url alexa country
-- --------- ------------------------- ----- -------
1 Google https://www.google.com/ 1 US
2 淘宝 https://www.taobao.com/ 13 CN
3 菜鸟教程 https://www.runoob.com/ 4689 CN
4 微博 https://weibo.com/ 20 CN
5 Facebook https://www.facebook.com/ 3 US