Youtube Channel

SUB QUERY & Inline View

Sub query: 
A Query within the where clause or A select query within another select query is called sub query.

Example : Select * from employee where dno=(select dno from department);
Types :
  1. Inner or Normal sub query.
  2. Correlated  sub query.
Inner Query : 
  •  If sub query executed only once and returns single values. It is called Inner query.
  • Uses operator =,<,>,<> etc.

Example : select * from employee where dno=(select max(dno) from department);

Correlated Query : 
  • If sub query returns multiple values then it is correlated sub query.
  • Uses opeartors In,Not In, All, Any etc.
Example :  Department wise max salary with employee details.
 Select e.name,e.no,e.salary from employee e where salary=(select max(salary) from employee b where e.dno=b.dno group by b.dno):

Inline View :

Select query within the from clause instead of table or object name.
Example : Select * from (Select name,no,salary from employee);


Next PostNewer Post Previous PostOlder Post Home

0 comments: