SQL Exists Keyword

Table Of Contents:

  1. What Is SQL Exists Keyword?
  2. Syntax Of SQL Exists.
  3. Examples Of SQL Exists.

(1) What Is SQL Exists Keyword?

  • The EXISTS operator is used to look for the existence of a row in a given table that satisfies a set of criteria.
  • It is a Boolean operator that compares the result of the subquery to an existing record and returns true or false.
  • The returned value is true, if the subquery fetches single or multiple records and false if no record is matched.
  • It is used in the combination of the subquery and checks whether a row is returned through this subquery or not.

(2) Syntax Of SQL Exists Keyword.

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

(3) Examples Of SQL Exists Keyword.

Products Table:

Suppliers Table:

Example-1:

SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.supplierID AND Price < 20);

Example-2:

SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.supplierID AND Price = 22);

Leave a Reply

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