Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

DBMS%20Interview%20Questions%20and%20Answers

Question: What is a Sub-Query?
Answer:
A query nested inside a SELECT statement is known as a subquery and is an alternative to
complex join statements. A subquery combines data from multiple tables and returns results
that are inserted into the WHERE condition of the main query. A subquery is always enclosed within parentheses and returns a column. A subquery can also be referred to as an inner query and the main query as an outer query. JOIN gives better performance than a subquery when you have to check for the existence of records. 
For example, to retrieve all EmployeeID and CustomerID records from the ORDERS table that have the EmployeeID greater than the average of the EmployeeID field, you can create a nested query, as shown:
SELECT DISTINCT EmployeeID, CustomerID FROM ORDERS WHERE EmployeeID > (SELECT AVG(EmployeeID) FROM ORDERS)
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook