Can a JOIN be alias?

  • Something like this

    select join_alias.col11, join_alias.col21 from

    (table1 a INNER JOIN table2 b ON a.col11=b.col21) join_alias

    Hope it makes sense.

    Please let me know.

  • icata (10/23/2012)


    Something like this

    select join_alias.col11, join_alias.col21 from

    (table1 a INNER JOIN table2 b ON a.col11=b.col21) join_alias

    Hope it makes sense.

    Please let me know.

    Don't think it exists in a format similar to the one you specified above, but you could potentially use a VIEW that does the join, which then you could alias in your main query.

    So something like:

    select join_alias.col11, join_alias.col21

    from vw_Tbl1JoinTbl2OnCol1 as join_alias

    -----------------
    ... Then again, I could be totally wrong! Check the answer.
    Check out posting guidelines here for faster more precise answers[/url].

    I believe in Codd
    ... and Thinknook is my Chamber of Understanding

  • There's no need to create a view. You'll end up with millions of views that you won't use.

    You need to specify the complete query, not just the join. Something like this.

    SELECT join_alias.col11,

    join_alias.col21

    FROM

    (SELECT a.col11, b.col21

    FROM table1 a

    INNER JOIN table2 b ON a.col11=b.col21) join_alias

    You can add as many columns as you need to your subquery.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (10/23/2012)


    There's no need to create a view. You'll end up with millions of views that you won't use.

    +1

    or even use a CTE.

    -----------------
    ... Then again, I could be totally wrong! Check the answer.
    Check out posting guidelines here for faster more precise answers[/url].

    I believe in Codd
    ... and Thinknook is my Chamber of Understanding

  • ib.naji (10/23/2012)


    Luis Cazares (10/23/2012)


    There's no need to create a view. You'll end up with millions of views that you won't use.

    +1

    or even use a CTE.

    +1 again for the CTE

    with join_alias as

    (SELECT a.col11, b.col21

    FROM table1 a

    INNER JOIN table2 b ON a.col11=b.col21)

    select col11,col21

    from join_alias

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply