Summary -

In this topic, we described about the Inline View with detailed example.

INLINE VIEW is the SELECT statement in another SELECT statement of FROM clause. INLINE VIEW is used to reduce complexity in queries without using JOIN.

Syntax -

SELECT column1,column2,… FROM (INLINE VIEW);

Example –

let us consider employee_ table as follows -

employee_details -

emp_id emp_name designation manager_id date_of_hire salary dept_id
001 Employee1 Director 2019-07-11 45000.00 1000
002 Employee2 Director 2019-07-11 40000.00 2000
003 Employee3 Manager Employee1 2019-07-11 27000.00 1000
004 Employee4 Manager Employee2 2019-10-08 25000.00 2000
005 Employee5 Analyst Employee3 2019-07-11 20000.00 1000
006 Employee6 Analyst Employee3 2019-10-08 18000.00 1000
007 Employee7 Clerk Employee3 2019-07-11 15000.00 1000
008 Employee8 Salesman Employee4 2019-09-09 14000.00 2000
009 Employee9 Salesman Employee4 2019-10-08 13000.00 2000

Scenario – Getting rows from table by using INLINE VIEW.

Requirement – Getting rows from employee_details by using INLINE VIEW. The query was as follows –

SELECT MAX(salary) AS max_salary 
FROM (SELECT salary
 FROM employee_details) AS max_salary; 

By executing above query, we can get maximum salary from employee_details table by using INLINE VIEW statement. The query was as follows –

Max_salary
45000.00

Advantages -

  • There is no necessary to create a temporary table.
  • We can get required rows by using a single query.