Editorial / Best Answer
Answered by:
Sailaja Pasupuleti
A sub-query is a part of query. Sub-queries are useful to find unknown value(s).
Ex: To find details of employees who are getting maximum salary.
In this requirement, the maximum salary not mentioned.
Solution:
To find maximum salary,
select max(sal) from emp;
For that maximum salary the employee details,
select * from emp where sal = (select max(sal) from emp);
So, in the above query, "select max(sal) from emp" is also a query but it returns a value (unknown or not given) and compares with "sal" column. This query is called sub-query.
What is the sub-query
Editorial / Best Answer
Answered by: Sailaja Pasupuleti
A sub-query is a part of query. Sub-queries are useful to find unknown value(s).
Ex: To find details of employees who are getting maximum salary.
In this requirement, the maximum salary not mentioned.
Solution:
To find maximum salary,
select max(sal) from emp;
For that maximum salary the employee details,
select * from emp where sal = (select max(sal) from emp);
So, in the above query, "select max(sal) from emp" is also a query but it returns a value (unknown or not given) and compares with "sal" column. This query is called sub-query.
Related Answered Questions
Related Open Questions