SQL | The IN Operator

SQL Webp

The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax:

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

IN Operator Example

The “Persons” table:

Table displaying person records with columns for P_Id, LastName, FirstName, Address, and City.

Now we want to select the persons with a last name equal to “Hansen” or “Pettersen” from the table above. We use the following SELECT statement:

SELECT * FROM Persons
WHERE LastName IN ('Hansen','Pettersen')

The result-set will look like this:

A table displaying a SQL result-set with columns for P_Id, LastName, FirstName, Address, and City. The rows show persons with the last names Hansen and Pettersen along with their first names, addresses, and cities.

Leave a Reply

Discover more from Geeky Codes

Subscribe now to keep reading and get access to the full archive.

Continue reading