What is an Inline View in SQL? Provide an example of an inline view as well.

Some database implementations, like Oracle, allow you to use a subselect in the FROM clause of a query. This SQL construct is also known as inline view, and it lets the subquery to be treated like a predefined view or table, even though an inline view is not predefined.

An inline view is basically a subquery, except it is always in the FROM clause of a SQL statement. The reason it is called a view is because it essentially functions as a view as far as the entire query is concerned.

But, remember that an inline view only exists in the query in which it is created – that is why they are called inline views. So, inline views are not actually part of the database schema because they are not real views. Take a look at our very simple example of an inline view:

SQL Example of Inline View

select max(age) 
from (
-- this part of the query is an inline view:
select age from table
) 

Of course, instead of using an inline view in the query above, you can simply write something like “select max(age) from table”, but this example was chosen for it’s simplicity in illustrating what an inline view would look like, certainly not for its real world applicability.

Inline View vs Derived Tables

Is there a difference between inline views and derived tables? No, they both actually refer to exactly the same thing. You can also read about derived tables here: Derived tables.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.

Leave a Reply

Your email address will not be published.