Get Started: SQL EXISTS Operator

In This Article, You Will Know About SQL EXISTS Operator. 

SQL EXISTS Operator – Before moving ahead, let’s know a bit about SQL HAVING Clause.

Table of Contents

The EXISTS operator is used to check whether any record exists in data or not. If records are found it returns True.

Syntax

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

Example Database

Table name: Data_1

S.No

Name

Class

1

Alex

5

2

Rolex

6

3

Salex

7

4

Jalex

8

5

Kalex

9

Table name: Data_2

S.No

Roll_No

Section_ID

6

451

A

7

452

B

8

453

C

9

454

C

10

455

C

SQL EXISTS Example

Example: Use the EXISTS operator to return  the records from the data.

				
					SELECT Name
FROM Data_1
WHERE EXISTS ( SELECT Class FROM Data_1 WHERE Data_1.S.No = Data_2.S.No )
				
			

Example: Use the EXISTS operator to return the records from the data.

				
					SELECT Name
FROM Data_1
WHERE EXISTS ( SELECT Class FROM Data_1 WHERE Data_1.S.No = Data_2.S.No AND Section_ID = ‘C’);
				
			

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

2 thoughts on “Get Started: SQL EXISTS Operator”

Leave a Comment

Stay in the loop

codingstreets