Sunday, July 16, 2023

MySQL IN Operator

                    MySQL 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.

IN Syntax

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

OR

SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);

Demo Database

The table below shows the complete “Employees” table from the database:

IN Operator Examples

The following SQL statement selects all Employees that are located in “London”, “Seattle” or “Kent”:

Example

SELECT * FROM Employees
WHERE City IN ('London', 'Seattle', 'Kent');

The following SQL statement selects all Employees that are NOT located in “London”, “Seattle” or “Kent”:

Example

SELECT * FROM Employees
WHERE City NOT IN ('London','Seattle', 'Kent');

No comments:

Post a Comment

Building Static Website(part6) HTML Lists

  Building Static Website (part6) HTML Lists Today, let us add some lists to our detailed view section by using html lists. Lists: List is a...