SQL IN 操作符

SQL IN 操作符 #

IN 操作符 #

IN 操作符允许您在 WHERE 子句中规定多个值。

SQL IN 语法 #

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...);

IN 操作符实例 #

下面的 SQL 语句选取 icp 为 “google” 或 “dnspod.cn” 的所有网站:

MariaDB [learnsql]> select * from domains where icp in ('google','dnspod.cn');
+----+-----------+--------------+------------+------------+
| ID | ICP       | DomainName   | RegDate    | EndDate    |
+----+-----------+--------------+------------+------------+
| 22 | google    | suopo.net    | 2020/6/17  | 2023/6/17  |
| 43 | dnspod.cn | zjq.xyz      | 2021-08-06 | 2022-10-24 |
| 44 | dnspod.cn | alair.cn     | 2021-08-06 | 2022-12-10 |
| 45 | dnspod.cn | ymqd.net     | 2022-01-28 | 2023-03-03 |
| 46 | dnspod.cn | nasplus.cn   | 2022-01-28 | 2023-03-08 |
| 47 | dnspod.cn | manjushri.cn | 2022-01-28 | 2023-03-11 |
| 48 | dnspod.cn | pushto.cn    | 2022-01-28 | 2023-03-12 |
| 49 | dnspod.cn | gfwlist.cn   | 2022-01-28 | 2023-03-23 |
| 50 | dnspod.cn | byhzg.cn     | 2022-01-28 | 2023-04-14 |
+----+-----------+--------------+------------+------------+
9 rows in set (0.004 sec)