📅  最后修改于: 2020-12-02 04:53:15             🧑  作者: Mango
SQL Server IN条件用于避免SELECT,INSERT,UPDATE或DELETE语句中出现多个OR条件。
句法
expression IN (value1, value2, .... value_n);
表达式:它指定要测试的值。
value1,value2,.. value_n:它指定要针对表达式测试的值。
注意:SQL Server IN条件也称为SQL Server IN运算符。
使用IN条件比较字符串值的SQL Server SELECT语句:
SELECT *
FROM [javatpoint].[dbo].[Employees]
WHERE name IN ('Mahesh', 'Lily', 'Rahul');
输出:
要么
SELECT *
FROM [javatpoint].[dbo].[Employees]
WHERE name = 'Mahesh'
OR name = 'Lily'
OR name = 'Rahul';
输出:
使用IN条件比较数字值的SQL Server SELECT语句:
SELECT *
FROM [javatpoint].[dbo].[Employees]
WHERE id IN (14, 13, 9, 11, 10);
输出:
要么
SELECT *
FROM [javatpoint].[dbo].[Employees]
WHERE id = 14
OR id = 13
OR id = 9
OR id = 11
OR id = 10;
输出:
使用IN条件和NOT运算符的SQL Server SELECT语句:
SELECT *
FROM [javatpoint].[dbo].[Employees]
WHERE name NOT IN ('Mahesh', 'Lily', 'Rahul');
输出:
要么
SELECT *
FROM [javatpoint].[dbo].[Employees]
WHERE name <> 'Mahesh'
AND name <> 'Lily'
AND name <> 'Rahul';
输出: