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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:01:47+00:00 2026-05-21T04:01:47+00:00

I have a table with a lot of data and I need to join

  • 0

I have a table with a lot of data and I need to join it with some other large tables.

Only a small portion of my table is actually relevant for me each time.

When is it best to filter my data?

  1. In the where clause of the SQL.

  2. Create a temp table with the specific data and only then join it.

  3. Add the predicate to the first inner join ON clause.

  4. Some other idea.

1.

Select * 
From RealyBigTable
Inner Join AnotherBigTable On …
Inner Join YetAnotherBigTable On …
Where RealyBigTable.Type = ?

2.

Select * 
Into #temp
From RealyBigTable
Where RealyBigTable.Type = ?

Select * 
From #temp
Inner Join AnotherBigTable On …
Inner Join YetAnotherBigTable On …

3.

Select * 
From RealyBigTable
Inner Join AnotherBigTable On RealyBigTable.type = ? And … 
Inner Join YetAnotherBigTable On …

Another question:
What happens first? Join or Where?

  • 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-21T04:01:48+00:00Added an answer on May 21, 2026 at 4:01 am

    Because you are using INNER JOINs the WHERE or JOIN debate only depends on your taste and style. Personally, I like to keep the links between the two tables (e.g. foreign key constraint) in the ON clause, and actual filters against data in the WHERE clause.

    SQL Server will parse the query into the same token tree, and will therefore build identical query execution plans.

    If you were using [LEFT/RIGHT] OUTER JOINS instead, it makes a world of difference since not only is the performance probably different, but also very likely the results.


    To answer your other questions:

    When is it best to filter my data?

    1. In the where clause of the SQL.
    2. Create a temp table with the specific data and only then join it.
    3. Add the predicate to the first inner join ON clause.
    4. Some other idea.

    In the WHERE or ON clause, both are seen as the same. For 3, the “first inner join” has no relevance. In a multi-table INNER JOIN scenario, it really doesn’t matter which goes first (in the query), as the query optimizer will shuffle the order as it sees fit.

    Using a temp table is completely unnecessary and won’t help, because you are having to extract the relevant portion anyway – which is what a JOIN would do as well. Moreover, if you had a good index on the JOIN conditions/WHERE filter, the index will be used to only visit the relevant data without looking at the rest of the table(s).

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

Sidebar

Related Questions

I have multiple tables with a lot of data in it. I'm only mentioning
I have a table with a lot of repeated data that I'd like to
i have a table with a lot of stuff, i need to parse it
I have a table that contains a lot of data, where we particularly care
I have the very table in sql server 2008 with lot of data |ID|Name|Column_1|Column_2|
So I have a lot of data in a spreadsheet and I need to
I have a table with a lot of text inputs like these: alt text
I have a table with a lot of records (could be more than 500
I have a table with a lot of rows, which makes the page scroll.
I have a table with a whole lot of numerical values in it, i

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.