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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:57:40+00:00 2026-05-23T00:57:40+00:00

I have two queries serving the same purpose. SELECT * FROM #user INNER JOIN

  • 0

I have two queries serving the same purpose.

SELECT * FROM #user 
    INNER JOIN #department ON #user.departmentId = #department.departmentId
    INNER JOIN #user manager ON #department.departmentHead = manager.userid
WHERE #department.DepartmentName= 'QA'

SELECT * FROM #user 
    INNER JOIN #department ON #department.DepartmentName= 'QA' AND #user.departmentId = #department.departmentId 
    INNER JOIN #user manager ON #department.departmentHead = manager.userid

The table structure is as follows.

create table #user
(
    userid int identity(1,1),
    userName varchar(20),
    departmentId int
)

create table #department
(
    departmentId int identity(1,1),
    departmentName varchar(50),
    departmentHead int
)

I am expecting some difference between the two queries, in the performance perspective. My assumption/understanding is that the first query gets executed in this order.

  1. Join all the records of user and department tables.

  2. Join the result of step 1 with all the records of Users table again.

  3. Apply WHERE condition (Department = ‘QA’).

Whereas the second one

  1. Join all the QA department records (filtered set) with the users table.

  2. Join the results of step 1 with all the records of user table.

I am assuming that the second query to be more efficient than the first one since the second query applies the filter at an early stage of execution saving the followers to deal with less number of records.

But SQL Execution plan doesn’t show any difference between the two queries. Please explain this and validate if my understanding on the order of filter application is correct.

  • 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-23T00:57:42+00:00Added an answer on May 23, 2026 at 12:57 am

    Actually SQL server has statistical data about your tables and can rearange the joins to create a more optimal execution plan.

    Query hint FORCE ORDER specifies that the join order indicated by the query syntax is preserved during query optimization. But dont use that unless you have a performance problem.

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

Sidebar

Related Questions

I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have two queries select TC,li,it as ee from results where li = not_applicable
I have two different queries: SELECT PB_BANK_CODE, PB_BANK_NAME FROM GLAS_PDC_BANKS WHERE PB_COMP_CODE='1' AND PB_BANK_CODE='025'
I have two sql queries select * from table1 ORDER BY column1 Select top
I have two select queries: SELECT MONTH(date) AS month, count(DISTINCT ip) FROM table_name WHERE
I have two queries Dim query1 as String = Select * from openquery (devbook,
I have two queries that I run in the same table: SELECT id, COUNT(up)
I have two queries to get related tags from a mysql database, one works,
i have two queries, querying the same table, but based on different parameters, i
I have two queries that produce the same output. One is using the Intersect

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.