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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:13:04+00:00 2026-05-30T21:13:04+00:00

SQL server 2008 on WINDOWS 2008 Please compare following sqls: 1. select count(*) from

  • 0

SQL server 2008 on WINDOWS 2008

Please compare following sqls:

1.

select count(*) 
from Trades t 
inner join UserAccount ua on ua.AccID = t.AccID

2.

select count(*) 
from Trades t 
inner join (
    select * 
    from UserAccount ua 
    where ua.UserID = 1126
) as theua on theua.AccID = t.AccID

3.

select count(*) 
from Trades t 
inner join UserAccount ua on ua.AccID = t.AccID 
where ua.UserID=1126

Given Trades has millions of rows and UserAccount is a quite small table. And AccID can be duplicative.

Execution result:

  1. 234734792
  2. 8806144
  3. 8806144

I expect No.2 can be at least as fast as No.1, but actually it’s much slower even slower than No.3
Time consumption:

  1. 2 secs
  2. 10 secs
  3. 8 secs

Could someone explain the reason? And is it possible to make it faster when I need a filter like UserID=1126?

  • 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-30T21:13:05+00:00Added an answer on May 30, 2026 at 9:13 pm
    1. is the fastest since it has the least amount of where conditions.
      (The missing UserID)

    2. is the slowest because it has an inner select which has to execute for each join
      (btw: never do this)

    3. is slower than #1 because of the extra where condition (UserID). This is the query you want to use.
      (You could also swap the “where” for an “and” directly after the join on)

    Do you have foreign keys set up?

    Also make sure you have the appropriate Indexes (IE: AccID & UserID).

    From SSMS, run the query with the Execution Plan on and it will show you potential inefficiencies in the query / indexes you should create.

    In the execution plan you should look out for things like tables scans. What you want to see are seeks.

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

Sidebar

Related Questions

I installed SQL Server 2008 Enterprise Edition on Windows 7 Ultimate from sadegh user.
I'm running SQL Server 2008 Express on Windows XP on a VirtualPC instance inside
I'm setting up a dedicated SQL Server 2005 box on Windows Server 2008 this
I have just installed SQL Server 2008 including Reporting Services on Windows Server 2003.
I am running windows server with asp.net websites and sql server 2008 and IIS
I have 1 PC (Windows Server 2003 + SQL Server 2008) and 2 PCs
My configuration: windows XP SP3 JDBC 2005 MS SQL Server 2008 Express, exposed via
I'm trying to working with Openrowset on SQL Server 2008 R2 installed in Windows
I have created an Amazon EC2 Instance that provides Windows Server 2008 with SQL
I am developing an Windows pplication(using Visual Studio 2008,Sql server 2005). I have to

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.