SQL Server IN Clause: Explained with Examples

SQL Server IN clause featured image
Reading Time: 2 minutes

The SQL Server IN clause is a very helpful tool we can use to simplify our queries. In this very brief tutorial, we’ll discuss how the IN clause works and provide examples of it’s use.



Take the following Books table:

SQL Server IN clause Books table

What if we wanted to write a query where we display book details where the author is either Allen, Tracy, or Newport?

We could write a query using several OR operators:

SQL Server IN clause using OR operators

But a better tool is the IN clause. With the IN clause, you simply outline a comma-separated list of values you want your column to match on, like this:

SQL Server IN clause Example

Much easier!

And your list of values can be any data type. For example, we can use the IN clause to find books where the Pages value is either 283, 256, or 224:

SQL Server IN clause using integers

It’s as simple as that!



Next Steps:

Leave a comment if you found this tutorial helpful!

Do you know how the IF EXISTS decision structure works? Click the link to find out!

You might also benefit from reading the following FREE guide:

FREE EBook on SQL Server Data Types!

SQL Server offers many data types that one can use when developing databases. This guide discusses the most common data types you will likely see during your career as a database professional. You won’t regret owning this guide, trust me. Download it today!



Thank you very much for reading!

Make sure you subscribe to my newsletter to receive special offers and notifications anytime a new tutorial is released!

If you have any questions, please leave a comment. Or better yet, send me an email!

Related Post

Leave a Reply

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