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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:21:33+00:00 2026-05-25T12:21:33+00:00

If a query contains a join with multiple join constraints, are the constraints evaluated

  • 0

If a query contains a join with multiple join constraints, are the constraints evaluated in left to right order or does SQL Server decide the optimum way to evaluate them?

In hopes of clarifying, I’ll try to explain why I’m asking. Let’s say I have a table named Alpha and it has two columns in addition to a standard ID. The first column is named Generic1 and is a varchar(20). The second is named Type and is a smallint. If Type = 1 then the value of Generic1 will actually be the ID of a record in another table (lets call it Bravo). If Type = 2 then the value of Generic1 will be some plain text value.

I want to write the following query:

select * from Beta b
left outer join Alpha a on a.Type = 1 and a.Generic1 = b.ID

If I can safely assume that SQL Server will only attempt the comparison of a.Generic1 = b.ID AFTER it has compared a.Type = 1, then I don’t have to worry about cast/conversion errors. I would like the SQL to avoid using syntax that is only valid in SQL Server if possible.

I’m guessing that SQL Server evaluates them as it sees fit, so I’ll have to add a CAST to be safe.

  • 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. Editorial Team
    Editorial Team
    2026-05-25T12:21:34+00:00Added an answer on May 25, 2026 at 12:21 pm

    Why do you have a mixed column like this? Sounds like there should be a FK relationship to Bravo which at the moment presumably you have no way of enforcing.

    Anyway assuming you are stuck with this schema no order of evaluation is guaranteed in SQL Server. You would need to do something like

    ... ON a.Type = 1 AND CASE WHEN ISNUMERIC(a.Generic1) = 1 
                        THEN a.Generic1 END = b.ID 
            /* Result of "CASE" implicitly cast to int*/
    

    (Though you might want to use a method specifically for integers instead though as isnumeric does not guarantee that a value will successfully cast to int)

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

Sidebar

Related Questions

How can I escape a bracket in a full-text SQL Server contains() query? I've
Does anyone know of a way to do a left outer join with SubSonic
I've got a question regarding a SQL-select-query: The table contains several columns, one of
Assuming A.sql contains the following code, then second Select query won’t be executed due
I am using FOR XML in a query to join multiple rows together, but
We have the following query to give us a left outer join: (from t0
This is my query thus far: select C.ACCOUNTNO,C.CONTACT,KEY1,KEY4 from contact1 C left join CONTSUPP
I'm getting an error when trying to join against multiple tables in a query:
In SQL 2005 stored proc I need to run a query that contains a
I need to join a contact table (contacts) that contains names multiple times in

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.