Table of Contents
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 Sub Query on Sample Table:

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 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.

Comments (No)