0% found this document useful (0 votes)
86 views5 pages

The SQL EXISTS Operator

Uploaded by

Bharath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views5 pages

The SQL EXISTS Operator

Uploaded by

Bharath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL 

EXISTS Operator
❮ PreviousNext ❯

The SQL EXISTS Operator


The EXISTS operator is used to test for the existence of any record in a subquery.

The EXISTS operator returns TRUE if the subquery returns one or more records.

EXISTS Syntax
SELECT column_name(s)
FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);

Demo Database
Below is a selection from the "Products" table in the Northwind sample
database:

ProductID ProductName SupplierID CategoryID Unit

1 Chais 1 1 10 boxes x 2

2 Chang 1 1 24 - 12 oz bo
3 Aniseed Syrup 1 2 12 - 550 ml b

4 Chef Anton's Cajun Seasoning 2 2 48 - 6 oz jars

5 Chef Anton's Gumbo Mix 2 2 36 boxes

And a selection from the "Suppliers" table:

SupplierI SupplierName ContactName Address City P


D e

1 Exotic Liquid Charlotte 49 Gilbert St. London E


Cooper

2 New Orleans Cajun Shelley Burke P.O. Box 78934 New 7


Delights Orleans

3 Grandma Kelly's Regina Murphy 707 Oxford Rd. Ann Arbor 4


Homestead

4 Tokyo Traders Yoshi Nagase 9-8 Sekimai Musashino- Tokyo 1


shi

SQL EXISTS Examples


The following SQL statement returns TRUE and lists the suppliers with a product
price less than 20:

Example
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID
= Suppliers.supplierID AND Price < 20);
Try it Yourself »

The following SQL statement returns TRUE and lists the suppliers with a product
price equal to 22:

Example
SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID
= Suppliers.supplierID AND Price = 22);
Try it Yourself »

❮ PreviousNext ❯

COLOR PICKER

LIKE US
  

Get certified
by completing
a course today!

w3schoolsCERTIFIED.2021
Get started

CODE GAME
Play Game

REPORT ERROR
FORUM
ABOUT
SHOP

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples

Web Courses
HTML Course
CSS Course
JavaScript Course
Front End Course
SQL Course
Python Course
PHP Course
jQuery Course
Java Course
C++ Course
C# Course
XML Course
Get Certified »

W3Schools is optimized for learning and training. Examples might be simplified


to improve reading and learning. Tutorials, references, and examples are
constantly reviewed to avoid errors, but we cannot warrant full correctness of
all content. While using W3Schools, you agree to have read and accepted
our terms of use, cookie and privacy policy.

Copyright 1999-2021 by Refsnes Data. All Rights Reserved.


W3Schools is Powered by W3.CSS.

You might also like