Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • EXISTS Operator

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 424
    Comment on it

    EXISTS Operator:

    Exists operator is a special type of operator which is used in a subquery. It is used to check whether a subquery returns something or not. If a subquery returns some row then outer query get executed otherwise the whole query will return nothing.

    Syntax:

    SELECT columnname(s)
    FROM tablename
    WHERE EXISTS
    (SELECT *
    FROM tablename2"
    WHERE "condition");

    We can use EXISTS operator with DELETE , UPDATE OR DELETE statements other than SELECT statement.

    Example:

    SELECT *
    FROM Employee
    WHERE EXISTS (SELECT *
                  FROM Payroll
                  WHERE Employee.Emp_id = Payroll.P_id);

    This query will return rows only if the inner query will get executed successfully (return some data).

     

    Example of Exists operator with Delete query:

    DELETE FROM Employee WHERE 
     EXISTS (SELECT * FROM Payroll WHERE 
     Payroll.p_id = Employee.Emp_id);

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: