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 1030249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:40:13+00:00 2026-05-16T12:40:13+00:00

(this question is very similar to my previous question Does it matter where I

  • 0

(this question is very similar to my previous question Does it matter where I check part of a composite key when joining two tables in SQL Server?)

I’m joining three tables on a composite key, with the value of one of the columns being determined by user input. I’m wondering if it matters where I compare the corresponding columns when I do the joins.

Say I have a table, TableA, with columns ColAFoo, ColAFoo2, and ColABar. TableA has a composite primary key comprising ColAFoo and ColAFoo2 (PK_TableA).

I also have TableB, with ColBFoo, ColBFoo2, and ColBOther. TableB’s columns ColBFoo and ColBFoo2 comprise a foreign key to TableA’s primary key (FK_TableA_TableB).

Finally, I have TableC, with ColCFoo, ColCFoo2, ColCBlah, and ColCBlah2. TableC’s columns ColCFoo and ColCFoo2 comprise a foreign key to TableA’s primary key (FK_TableA_TableC). I’ll also say that TableC has a composite primary key comprising ColCFoo, ColCFoo2, and ColCBlah.

I need to join the three tables on the key. Is there a difference between the following (contrived) statements in terms of performance?

SELECT *
  FROM TableA a
  JOIN TableB b
    ON  a.ColAFoo = b.ColBFoo
        AND a.ColAFoo2 = b.ColBFoo2
  JOIN TableC c
    ON  a.ColAFoo = c.ColCFoo
        AND a.ColAFoo2 = c.ColCFoo2
  WHERE a.ColAFoo2 = @userInput

SELECT *
  FROM TableA a
  JOIN TableB b
    ON  a.ColAFoo = b.ColBFoo
        AND a.ColAFoo2 = b.ColBFoo2
  JOIN TableC c
    ON  a.ColAFoo = c.ColCFoo
  WHERE a.ColAFoo2 = @userInput
        AND c.ColCFoo2 = @userInput

SELECT *
  FROM TableA a
  JOIN TableB b
    ON  a.ColAFoo = b.ColBFoo
  JOIN TableC c
    ON  a.ColAFoo = c.ColCFoo
  WHERE a.ColAFoo2 = @userInput
        AND b.ColBFoo2 = @userInput
        AND c.ColCFoo2 = @userInput
  • 1 1 Answer
  • 2 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. Editorial Team
    Editorial Team
    2026-05-16T12:40:14+00:00Added an answer on May 16, 2026 at 12:40 pm

    No. The query optimiser will recognise if these are all the same.

    Best thing to do with this sort of question is just to look at the estimated execution plans and see if there are any differences.

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

Sidebar

Related Questions

This is very similar to a previous question (and may be the exact same
I know this is very similar to a previous question that I had posted,
This question is very similar to a previous one here: race-condition in pthread_once()? It
This looks very similar to my previous question because it's some sort of follow
This question is very similar (or almost identical) to In a non blocking socket
This question is very similar to an earlier question I asked ( This Question
My question is very similar to this question - Addin parameter for Oracle except
I know that this question is very similar to the question posted here .
This is a very similar question to this SO thread on middleware and views
I had asked a question very much similar to this in the thread: https://stackoverflow.com/questions/11259474/store-the-numericals-in-char-array-into-an-integer-variable-in-vc

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.