MySQL Sub Query with Exists and Not Exists

MySQL Sub Query:

MySQL Sub Query is a query nested within another query such as SELECT, INSERT, UPDATE or DELETE.

MySQL Sub Query with Exists and Not Exists:

When a subquery is used with the EXISTS or NOT EXISTS operator, a subquery returns a Boolean value of TRUE or FALSE.

MySQL Sub Query Syntax:

SELECT column_name (s)
FROM table1
WHERE
(SELECT column_name FROM table2)

MySQL Exists Syntax:

SELECT column_name (s)
FROM table1
WHERE EXISTS
(SELECT column_name FROM table2)

MySQL Not Exists Syntax:

SELECT column_name (s)
FROM table1
WHERE NOT EXISTS
(SELECT column_name FROM table2)

Sample Table:

MySQL New Sample Table
sample city table in mysql

MySQL Sub Query on Sample Table:

MySQL Sub Query Code Unit

MySQL EXISTS Operator on Sample Table:

  • If cn_name (London) exists in the city table, then it will fetch all data of the field (name) contained in the student table.
MySQL EXISTS Operator

MySQL NOT EXISTS Operator on Sample Table:

  • If cn_name (England) not exists in the city table, then it will fetch all data of the field (name) contained in the student table.
MySQL NOT EXISTS Operator

Artificial Intelligence (AI)
Email (Electronic Mail)

FTP (File Transfer Protocol)

Operating System (OS)
Information Security in E-Commerce
Careers in Information Technology (IT)
MySQL– Wikipedia

Comments (No)

Leave a Reply