Home » DBMS

Nested Queries, Correlated Nested Queries and Set Comparison Operators in DBMS

In this tutorial, we are going to learn about the Nested Queries, Correlated Nested Queries and Set Comparison Operators in DBMS.
Submitted by Anushree Goswami, on June 14, 2019

Nested Queries

A query embedded in a query. This type of relation is termed as Nested Query and the Embedded Query is termed as a subquery.

For example: To find the names of employee who are department Id 103.

For example:

SELECT E.ename
FROM Employee E
WHERE E.id IN (SELECTD.id FROM Department D WHERE D.id = 103)

Correlated Nested Queries

These types of queries are nested queries which are independent or depend only on the same row of an outer query being an embedded query.

For example: To find the names of employee who are department Id 103.

SELECT E.ename
FROM Employee E
WHERE EXISTS (SELECT *x FROM Department D WHERE D.id = 103 AND D.id = E.id)

Set Comparison Operators

There are different types of set comparison operators like EXISTS, IN and UNIQUE. SQL also supports op ANY and op ALL, where op means arithmetic comparison operators such as <, <=, =, <>, >=, >. SOME are also one of the set comparison operators but it is similar to ANY.

For example: Find Employees whose salary is greater than an employee named Shivam.

SELECT E.id
FROM Employee E
WHERE E.salary>ANY (SELECTE2.salary FROM Employee E2 WHERE E2.ename = 'Shivam')





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.