Check out example codes for "if exists sql server". It will help you in understanding the concepts better.

Code Example 1

IF EXISTS (SELECT * FROM tblGLUserAccess WHERE GLUserName ='xxxxxxxx') 
BEGIN
   SELECT 1 
END
ELSE
BEGIN
    SELECT 2
END

Code Example 2

if exists(select 1 from table where id = 4)

Learn ReactJs, React Native from akashmittal.com