SQL IN Operator – Multiple Values In Condition

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 SQL BETWEEN operator but there is one big difference.

Difference between SQL operators IN and BETWEEN:

  • BETWEEN can be used to define range which is continuous
  • IN is used to define values which are discrete – uncontinuous

SQL IN Operator Syntax

As we can see below, 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”.

SELECT Date
FROM dbo.Table
WHERE Date IN ('2017-05-01', '2017-05-03');

Query above is equal to the query:

SELECT Date
FROM dbo.Table
WHERE Date = '2017-05-01' OR Date = '2017-05-03';

Operator IN holds the code clearer

Rate this post
Category: SQL Operators

About Ing. Jan Zedníček - Data Engineer & Controlling

My name is Jan Zednicek, and I have been working as a freelance Data Engineer for roughly 10 years. During this time, I have been publishing case studies and technical guides on this website, targeting professionals, students, and enthusiasts interested in Data Engineering particularly on Microsoft technologies as well as corporate finance and reporting solutions. 🔥 If you found this article helpful, please share it or mention me on your website or Community forum

Leave a Reply

Your email address will not be published. Required fields are marked *