Last modified date:
IN operator in t-sql is used in cases where we need to specify a condition e.g in WHERE clause to multiple discrete values at once. It is similar to BETWEEN operator but there is one big difference.
Difference between IN and BETWEEN:
- BETWEEN can be used to define range which is continuous
- IN is used to define values which are discrete – uncontinuous
IN Operator Syntax
WHERE Date IN ('2017-05-01', '2017-05-03');
As we can see, the operator is followed by a bracket and in it, the values are separated by a comma. There is a similar way to specify the data negatively by using prefix “NOT IN”.
Query above is equal to the query:
WHERE Date = '2017-05-01' OR Date = '2017-05-03';
Operator IN holds the code clearer