Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 181611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:47:39+00:00 2026-05-11T14:47:39+00:00

Does it matter which way I order the criteria in the ON clause for

  • 0

Does it matter which way I order the criteria in the ON clause for a JOIN?

select a.Name, b.Status from a inner join b on a.StatusID = b.ID 

versus

select a.Name, b.Status from a inner join b on b.ID = a.StatusID 

Is there any impact on performance? What if I had multiple criteria?

Is one order more maintainable than another?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:47:40+00:00Added an answer on May 11, 2026 at 2:47 pm

    JOIN order can be forced by putting the tables in the right order in the FROM clause:

    1. MySQL has a special clause called STRAIGHT_JOIN which makes the order matter.

      This will use an index on b.id:

      SELECT  a.Name, b.Status FROM    a STRAIGHT_JOIN         b ON      b.ID = a.StatusID 

      And this will use an index on a.StatusID:

      SELECT  a.Name, b.Status FROM    b STRAIGHT_JOIN         a ON      b.ID = a.StatusID 
    2. Oracle has a special hint ORDERED to enforce the JOIN order:

      This will use an index on b.id or build a hash table on b:

      SELECT  /*+ ORDERED */         * FROM    a JOIN    b ON      b.ID = a.StatusID 

      And this will use an index on a.StatusID or build a hash table on a:

      SELECT  /*+ ORDERED */         * FROM    b JOIN    a ON      b.ID = a.StatusID 
    3. SQL Server has a hint called FORCE ORDER to do the same:

      This will use an index on b.id or build a hash table on b:

      SELECT  * FROM    a JOIN    b ON      b.ID = a.StatusID OPTION (FORCE ORDER) 

      And this will use an index on a.StatusID or build a hash table on a:

      SELECT  * FROM    b JOIN    a ON      b.ID = a.StatusID OPTION (FORCE ORDER) 
    4. PostgreSQL guys, sorry. Your TODO list says:

      Optimizer hints (not wanted)

      Optimizer hints are used to work around problems in the optimizer. We would rather have the problems reported and fixed.

    As for the order in the comparison, it doesn’t matter in any RDBMS, AFAIK.

    Though I personally always try to estimate which column will be searched for and put this column in the left (for it to seem like an lvalue).

    See this answer for more detail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: JavaScript === vs == : Does it matter which “equal” operator I
According to the Puppet documentation: Order does not matter in a declarative language. If
I am developing a reporting application where a user can select(and order) reports from
Consider these two queries: SELECT *, 'b' AS b FROM someTable ORDER BY a
I've a strange question: Which is the smart/best way to order an array of
Does endianness matter at all with the bitwise operations? Either logical or shifting? I'm
It does not matter what programming language. Can anyone please give me an idea
I have a Python program (with Django - does this matter?) that I want
For doing development, does it matter what OS PHP is running on? In other
I need a simple parser generator. The language does not matter. It only has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.