Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Wednesday 6 August 2014

Inline views & Subqueries in Oracle

Inline views:-

Oracle allows us to use subset in FROM clause of a select query which is known as INLINE VIEW. It treats the inline view as predefine view even though it’s not predefined. It is called inline view because it functions like a view in a sub query.

Let’s have an example of inline view:-

Create employee table and insert some values in that:-



Create dept table and insert some values in that:-



Above we have created two table called employee and dept with some data in it.

Inline view query:-

If you want to fetch the count of records from one table and all the related records from other table then you can achieve this by below query:-



If you want to select max salary in each department then you can achieve this by below query:-     

Sub query in oracle:-

In oracle, we can define query in WHERE clause of the select statement. It is called sub query because it is a query in another query.

The difference between inline view and sub query is, inline view is used in FROM clause and sub query is used in WHERE clause.                      



Another example is:-





Read Also:-  Various types of Loops
Please provide your feedback in the comments section above. Please don't forget to follow.