AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

SQL in Operator


<< Previous Page
sql tutorial
Next Page >>
sql tutorial

SQL Tutorial » SQL in Operator

SQL "IN" (without quotes) operator allows you to specify multiple values in a " WHERE" clause.
SQL "IN" (without quotes) is a shorthand for multiple OR conditions.

Syntax1:

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

Syntax2:

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

Let's look at the "Users" table: We will have six columns as: "id", "first_name", "last_name", "country" and "city":

ID First Name Last Name Country City
1 Clark Kent USA Boston
2 Pire Joveau France Paris
3 Nicky Anderson USA New York
4 Pepe Martínez Spain Madrid
5 Peter Parker SUA New York

 

SQL IN Operator Examples

In the next examples we display people located in "USA" and "Spain"::

SELECT * FROM Users WHERE Country IN ('USA', 'Spain');

Output displayed:

ID First Name Last Name Country City
1 Clark Kent USA Boston
3 Nicky Anderson USA New York
4 Pepe Martínez Spain Madrid
5 Peter Parker SUA New York

Related subjects:
How to create database phpmyadmin? Select data form database Insert into SQL SQL update PSql delete row

Tags: SQL in operator, access, list, array, python, java, c++, visual studio, excel
What is the IN operator in SQL?
How do you use the IN operator in an SQL query?
Is in a logical operator in SQL?
What is == in SQL?

 

SQL IN operator

The next example SQL statement selects all customers that are NOT located in "USA" and "France":

SELECT * FROM Users
WHERE Country NOT IN ('USA', 'France');

Output displayed:

ID First Name Last Name Country City
4 Pepe Martínez Spain Madrid

 

SQL in Operator

If we have a supplier for a specific product in Spain as an example and we want to select all users who come from the same country as the supplier, SQL statement will look like this:

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

Output displayed:

ID First Name Last Name Country City
4 Pepe Martínez Spain Madrid

 



sql in operator, access, list, array, python, java, c++, visual studio, excel
What is the IN operator in SQL?
How do you use the IN operator in an SQL query?
Is in a logical operator in SQL?
What is == in SQL?
SQL in Operator - sql tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home - Database
SQL - Database
SQL Syntax
SQL Select Data
SQL Insert Data
SQL Update
SQL Delete Row
PHP mysqli_query()
SQL order
SQL Create Database
SQL Display Data
SQL Count()
SQL mysqli_connect
SQL create table
SQL Where And & Or
SQL like Syntax
SQL Between Operator
SQL IN Operator
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


jQuery replace...
jQuery replaceClass...
jQuery click ()...
jQuery switchClass()...
jQuery draggable()...
jQuery HTML...
jQuery scroll smooth...
jQuery scroll()...
jQuery stop()...
jQuery animate()...
jQuery SlideToggle()...
jQuery slideDown()...
jQuery slideUp()...
jQuery fadeToggle...
jQuery fadeOut()...
jQuery fadeIn()...
jQuery Effects - hide () and show ()...
jQuery Events...
jQuery Attributes...
jQuery Selectors...