SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Which join will first execute ?

    Is it possible to have INNER JOIN and LEFT JOIN together in a SQL query ?

    Which join will first execute ? Can you please explain

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    698
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    You can mix inner and outer joins as you need in a query.

    The order of execution is irrelevant, that depends on how the optimizer in the DBMS works. The query describes a result set and how that result set is materialised is not governed by the query.

    Do you have a specific problem?

  3. #3
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I have multi join ... I find it confusing how the records will be picked up finally

    example:

    table 1 left join table 2 inner join table3 left join table 4 .....

  4. #4
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry that is too vague to help you.
    If you actually put in an example with sample data to show your concerns someone may be able to help.
    Again though, the order the joins are performed in should be irrelevant to the query.

  5. #5
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there any tool which could help me to do left join and inner join visually together ?

  6. #6
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is it that you are trying to accomplish?

  7. #7
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my difficulty is whenever there are multiple inner join and left joins mixed ...I'm confused how the final result will be picked up . I'm stuck at this part.

    Is there any thumb rule to remember how the result will be picked up finally ?

    Please guide. Thanks

  8. #8
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by windowsxp View Post
    my difficulty is whenever there are multiple inner join and left joins mixed ...I'm confused how the final result will be picked up . I'm stuck at this part.

    Is there any thumb rule to remember how the result will be picked up finally ?

    Please guide. Thanks
    As stated before you can apply the JOINs in any order you wish, the outcome will be the same for all possible orders.

    For all intents and purposes you can assume they will be executed from left to right, but this is not necessarily the case as the database will figure out the order itself for each individual query.

    In other words

    (A JOIN B) JOIN C produces the same result as A JOIN (B JOIN C)

    * provided you use the same join criteria, of course
    * A, B, C can also be JOINs themselves; you can nest this as much as you like.

    The only exception I can think of is if you calculate something from two tables and then use that result to join with a third table, in which case the tables that the calculation is based on need to be joined first; this is pretty exceptional though - I can't remember ever doing this and I've been writing queries for 10+ years.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •