Instagram
youtube
Facebook
Twitter

MS SQL Server EXIST Operator

MS SQL Server EXISTS Operation

  • EXISTS Operator is used to check the existence of any record or result of the correlated nested query.
  • If subquery return one or more records the EXISTS operator returns TRUE.
  • If the subquery returns a zero result the EXISTS operator returns FALSE. 
  • Syntax:
WHERE EXISTS(subquery);

Example:

We have two tables 'student' and 'staff' in the University database

SELECT * FROM [University].[dbo].[Student] WHERE EXISTS (SELECT * FROM [University].[dbo].[Staff] WHERE Student.Branch = Staff.Branch);   
Id Name Branch CGPA
EN19CS301254 Ravi CSE 9.34
EN19CS301246 Savi CSE 8.23
EN19CS301248 Aayush CSE 7.25