Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • CTE in SQL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 308
    Comment on it

    CTE Common Type Expression

    For providing pivoting in tables say you want to view your data in such a form such that rows comes in form of columns and columns in form of rows. For doing that SQL provide facility to use CTE in SQL

    Ex : Suppose you have query in simple form

    1. SELECT * FROM (
    2. SELECT A.Address, E.Name, E.Age From Address A
    3. Inner join Employee E on E.EID = A.EID) T
    4. WHERE T.Age > 50
    5. ORDER BY T.NAME

    By converting it into CTE it will look like this

    1. With T(Address, Name, Age) --Column names for Temporary table
    2. AS
    3. (
    4. SELECT A.Address, E.Name, E.Age from Address A
    5. INNER JOIN EMP E ON E.EID = A.EID
    6. )
    7. SELECT * FROM T --SELECT or USE CTE temporary Table
    8. WHERE T.Age > 50
    9. ORDER BY T.NAME

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: