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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 641
    Comment on it

    Sub Queries:

    Sub Queries are those query which comes within another query and are written after the WHERE clause.They are also known as Inner query or nested query.

    It is used to return records that are used in the main query as a condition to filter the data to be fetched. It can be used with INSERT, SELECT, UPDATE, DELETE statements as well as with comparison operators like =, <, >, >=, <= . IN, NOT IN etc.

    Example of Subquery with SELECT Statement:

    SELECT max(salary) FROM Employee 
    WHERE salary NOT IN (SELECT max(salary) FROM Employee);
    

    The above is a sub query to find the second highest salary of Employees.

    Example of Subquery with DELETE Statement:

    DELETE FROM Employee   
    WHERE salary <  (SELECT MIN(salary) FROM payroll);
    

    The above sub query will delete those employee records whose salary are less than the minimum salary of Payroll table.

 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: