SQL Inline Query, Inline View and SubQuery
SQL Inline Query, Inline View and SubQuery
--======================================================================
--====================================================
-- Sql Inline Query
/* Inline Query is just the Select Statement */
--====================================================
Ex_1:-
select * from scott.emp
Ex_2:-
select * from scott.emp where deptno = 20
--===================================================
Sql Inline View
/* When we use SQL Subquery (A query within a query) in From clause of the select
statement it is called inline view. */
--====================================================
ex_3:-
select * from ( select * from scott.emp where deptno = 10) A
--====================================================
Sql Sub Query
Below are the type of sub-query:
If it present in SELECT list, it is called “sub-select”.
If it present in FROM clause, it is called “inline-query” or “inline-view” .
If it present in WHERE clause, it may be simple sub-query or “co-related sub-query”.
select * :- (Sub Query SELECT Section)
from scott.emp :- (Sub Query FROM Section)
where deptno = 10 :- (Sub Query WHERE Section)
(Sub Query SELECT Section)
--==================
select A.* ,
( select Z.DNAME from scott.dept Z where Z.DEPTNO = A.DEPTNO ) Department_name
from scott.emp A
(Sub Query FROM Section)
--==================
select A.*, Z.DNAME from scott.emp A, ( select DNAME, DEPTNO from scott.dept) Z
where A.deptno = Z.deptno
(Sub Query WHERE Section)
--==================
select * from Scott.emp A
where deptno > ( select deptno from scott.dept where deptno = 10)
/*
A subquery is used to return data that will be used in the main query based on condtion or Join
1.A subquery is a SQL query within a query.
2.Subqueries must be enclosed with parenthesis
3. if Subqueries returns individual values it means that is used as a column in our Main Query
if Subqueries returns list of records or multiple values it means that is used as a Inline view
or as a table in our Main Query
*/
--======================================================================
--====================================================
-- Sql Inline Query
/* Inline Query is just the Select Statement */
--====================================================
Ex_1:-
select * from scott.emp
Ex_2:-
select * from scott.emp where deptno = 20
--===================================================
Sql Inline View
/* When we use SQL Subquery (A query within a query) in From clause of the select
statement it is called inline view. */
--====================================================
ex_3:-
select * from ( select * from scott.emp where deptno = 10) A
--====================================================
Sql Sub Query
Below are the type of sub-query:
If it present in SELECT list, it is called “sub-select”.
If it present in FROM clause, it is called “inline-query” or “inline-view” .
If it present in WHERE clause, it may be simple sub-query or “co-related sub-query”.
from scott.emp :- (Sub Query FROM Section)
where deptno = 10 :- (Sub Query WHERE Section)
(Sub Query SELECT Section)
--==================
select A.* ,
( select Z.DNAME from scott.dept Z where Z.DEPTNO = A.DEPTNO ) Department_name
from scott.emp A
(Sub Query FROM Section)
--==================
select A.*, Z.DNAME from scott.emp A, ( select DNAME, DEPTNO from scott.dept) Z
where A.deptno = Z.deptno
(Sub Query WHERE Section)
--==================
select * from Scott.emp A
where deptno > ( select deptno from scott.dept where deptno = 10)
/*
A subquery is used to return data that will be used in the main query based on condtion or Join
1.A subquery is a SQL query within a query.
2.Subqueries must be enclosed with parenthesis
3. if Subqueries returns individual values it means that is used as a column in our Main Query
if Subqueries returns list of records or multiple values it means that is used as a Inline view
or as a table in our Main Query
*/
Comments
Post a Comment