SQL – In Operator

Table Of Contents:

  1. What Is An “In” Operator?
  2. Syntax Of “In” Operator.
  3. Examples Of “In” Operator.

(1) What Is An “In” Operator ?

  • The IN operator allows you to specify multiple values in a WHERE clause.
  • The IN operator is a shorthand for multiple OR conditions.

(2) Syntax Of “In” Operator ?

Syntax:

SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);

(3) Examples Of “In” Operator ?

Demo Data:

Example-1: Country in “Germany”, “France” or “UK”

SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');

Example-2: Country Not in “Germany”, “France” or “UK”

SELECT * FROM Customers
WHERE Country NOT IN ('Germany', 'France', 'UK');

Example-3: Selects all customers that are from the same countries as the suppliers:

SELECT * FROM Customers
WHERE Country IN (SELECT Country FROM Suppliers);

Leave a Reply

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