SQL EXISTS is use to check the existence of the result of subquery return. SQL EXISTS will test whether the subquery will return at least a single record, and if there is no data returned the operator returns 'FALSE' and it will not return any records with stop the execution.

However, the selected list in SQL EXISTS subquery is not used to execute the outer query and it will list out all the records of table selected as long as subquery return at least a single record.

The SQL syntax for the EXISTS operator is:

SELECT [COLUMN NAME] FROM [TABLE NAME]
WHERE EXISTS (
SELECT [COLUMN NAME] FROM [TABLE NAME]
WHERE [CONDITION])


EXAMPLE :

Table GameScores

PlayerNameDepartmentScores
JasonIT3000
IreneIT1500
JaneMarketing1000
DavidMarketing2500
PaulHR2000
JamesHR2000

Table PlayerGender

PlayerNameGender
JasonMale
IreneFemale
JaneFemale
DavidMale
PaulMale
JamesMale

SQL statement :

SELECT * FROM GameScores
WHERE EXISTS (SELECT * FROM PlayerGender WHERE Gender ='Male')

Result:

PlayerNameDepartmentScores
JasonIT3000
IreneIT1500
JaneMarketing1000
DavidMarketing2500
PaulHR2000
JamesHR2000