SQL IN Operator – Multiple Values In Condition

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

SELECT Date
FROM dbo.Table
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:

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

Operator IN holds the code clearer

My name is Jan Zedníček and I work as a BI Developer at Kentico Software in Brno. Mostly you can see me there working in the office, but I also work partly as a freelancer. I have been working as a freelancer for many companies for more than 5 years, but Kentico is the matter of my heart. I used to work as a financial controller at companies like Aero Vodochody or Sberbank and I also used to be a bond program manager in Unicapital Investment group. When I am not at work, I like playing volleyball, chess, doing a workout in the gym and I enjoy tasting of best quality rums. I am trying to summarize all my knowledge on this website not to forget them (because of the rum effect, you know =) and to put them forward to anyone. Don´t worry about asking for help or writing some comments.

Category: SQL Operators

About Ing. Jan Zedníček - BI Developer, Finance controller

My name is Jan Zedníček and I work as a BI Developer at Kentico Software in Brno. Mostly you can see me there working in the office, but I also work partly as a freelancer. I have been working as a freelancer for many companies for more than 5 years, but Kentico is the matter of my heart. I used to work as a financial controller at companies like Aero Vodochody or Sberbank and I also used to be a bond program manager in Unicapital Investment group. When I am not at work, I like playing volleyball, chess, doing a workout in the gym and I enjoy tasting of best quality rums. I am trying to summarize all my knowledge on this website not to forget them (because of the rum effect, you know =) and to put them forward to anyone. Don´t worry about asking for help or writing some comments.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.