SQL – Inline View and Sub Query

Spread the love

Inline View – it avoids , join operations and  can condense many separate queries into a single query.

Sub Query  – using parentheses embed a query within a query, to use a sub query can have many method at many place within a query.

BRANDS TABLE

S_NOPRODUCTMONTHYEARQTYSALES
1NIKEDEC2016107599
2REEBOKJAN2014903500
3FILAFEB201786000
4PUMAJAN2015165000
5NULLAPR201252500

ITEM_TYPE TABLE

PRODUCTQTYSALES
NIKE107599
REEBOK181200
FILA86000
PUMA165000
NULL52500

 

 

INLINE VIEW

SELECT A.* , B.TYPE
FROM ( SELECT PRODUCT , QTY ,SALES FROM BRAND WHERE PRODUCT IS NOT NULL AND SALES> 5000) AS A
LEFT JOIN ITEM_TYPES B
ON
A.PRODUCT = B.PRODUCT

 

Result

PRODUCTQTYSALESTYPE
NIKE107599SHOES
FILA86000SHOES

 

SUB QUERY

SELECT * FROM
            (
                   SELECT A.* , B.TYPE
                    FROM BRAND A
                    LEFT JOIN
                    ITEM_TYPES B
                    ON
                    A.PRODUCT = B.PRODUCT
             )
AS TEMP_SALES_TABLE

Result

S_NOPRODUCTMONTHYEARQTYSALESTYPE
1NIKEDEC2016107599SHOES
2REEBOKJAN2014181200TSHIRT
3FILAFEB201786000SHOES
4PUMAJAN2015165000RUNNING SHOES
5NULLAPR201252500NULL

 

 

 

difference between inline view and sub query search keyword
sql inline view vs sub query search keyword
inline view vs sub query in SQL search keyword
Write inline view and sub query in SQL search keyword
inline view in sql search keyword
sql inline view search keyword
inline view query writing search keyword
write query as inline view search keyword
query writing inline view search keyword
structure of inline view sql search keyword
easy method to write inline view query search keyword
remove complexity of query writing by inline view search keyword
Technics to write inline view query search keyword
structure of inline view query sql search keyword
sub query in sql search keyword
sql sub query search keyword
sub query query writing search keyword
write query as sub query search keyword
query writing sub query search keyword
structure of sub query sql search keyword
easy method to write sub query query search keyword
remove complexity of query writing by sub query search keyword
Technics to write sub query search keyword
structure of sub query query sql search keyword