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

  • Home
  • SEARCH
  • 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 6778267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:14:48+00:00 2026-05-26T16:14:48+00:00

When querying with MSSQL what is the most efficient way to grab a single

  • 0

When querying with MSSQL what is the most efficient way to grab a single column from a computed table and connect it to a result set.

Tables: mytable = 20k rows index on mytable.col1, othertable = 30k rows, no index on othertable.col1

Inline Query – Runs an query in the select statement

SELECT * FROM (
    SELECT col1, col2, col3, 
    col4 = (SELECT min(col5) FROM othertable o WHERE m.col1 = o.col1)
    row = ROW_NUMBER() OVER(ORDER BY somerow) 
    FROM mytable m
) as paged
WHERE row BETWEEN 1 AND 25

Join Query – Joins our table onto the computed table

SELECT * FROM (
    SELECT col1, col2, col3, o2.col5again
    row = ROW_NUMBER() OVER(ORDER BY somerow) 
    FROM mytable m
    JOIN (SELECT col1, min(col5) as col5again FROM othertable o GROUP BY col1) as o2 ON o2.col1 = m.col1
) as paged
WHERE row BETWEEN 1 AND 25

My gut instinct was the JOIN was faster. Yet, upon testing the inline query would finish in an average of 7 seconds while the other query would take >30 seconds when executed in MSSQL studio.

  1. Is using an inline select query really the best way to inject the single column?
  2. Does the query optimized wait to run the inline SELECT() statement until after the results have been paged, would that explain the different in running time?

FYI: In my specific example we added an index to othertable.col1 and it reduced the query time to 0s, but this question focuses more on whether the JOIN versus SELECT() is better.

  • 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-26T16:14:49+00:00Added an answer on May 26, 2026 at 4:14 pm

    Performance tuning is an art that involves understanding why plans are created the way they are, what each piece in the plan does, and how you can influence a more efficient path to be chosen.

    Missing covering indexes will cause scans (excessive reads). Too many indexes will slow down your DUI’s (Deletes, Updates, and Inserts). Outdated or missing statistics will cause the wrong join algorithm to be used and/or an inaccurate estimated row count (which could lead to paging).

    Run both queries in the same window and include the actual execution plan. This will split the plans up and tell you which one is more expensive. It will give you missing index hints. As you get better at reading plans, you’ll learn how to improve your query performance.

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

Sidebar

Related Questions

Querying a Nested Set Model table , here's the SQL... how can this be
This is a follow up from my question: MySQL: Querying a table and possibly
I was wondering if there is a way of querying in MSSQL Server (2005
I have the following MySQL query and tables from which I am querying: SELECT
I'm querying a bunch of information from cisco switches using SNMP. For instance, I'm
Well I am querying my DB, a table called bookBilling, to get a value
The db I am querying from is returning some null values. How do I
I am querying data from views that are subject to change. I need to
I am querying information from Active Directory . I have code that works, but
I have a problem querying multiple tables in MySQL and am currently at my

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.