The SQL EXISTS operator checks the existence of any record through a subquery.

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

SYNTAX

Where,

  • EXISTS                                             : keyword used checks the existence of any record in a table.

  • Table_name                                     : The name of the table from where you want to fetch the data

  • Column1Name, Column2Name        : The name of the columns of the table which you want to uniquely fetch.

EXAMPLE

Let’s consider two different tables: SalaryInfo and Persons. I want to fetch the salary details of all the people present in Persons table. Here is a DEMO DATABASE:

 

Figure 23.1. SELECT * FROM Persons;

 

Figure 23.2. SELECT * FROM SalaryInfo;

QUERY

Figure 23.3. EXISTS QUERY

OUTPUT

Figure 23.4. OUTPUT OF EXISTS QUERY

PRACTICE YOURSELF 

 
 
 

©2020 by Pavan Lalwani. 

  • Udemy
  • Facebook
  • Twitter
  • YouTube
  • Linkedin