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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:23:10+00:00 2026-05-28T03:23:10+00:00

I was wondering if a SELECT of a SELECT incurs any additional performance, or

  • 0

I was wondering if a SELECT of a SELECT incurs any additional performance, or if the database is smart enough to optimize this.

For example, I have some selects I do like the following:

SELECT a.year, b.month, c.day, totalVolume from 
(SELECT DATEPART(year, transactionTime) as year, 
        DATEPART(month, transactionTime) as month,
        DATEPART(day, transactionTime) as day,
        SUM(volume) as totalVolume FROM DOW30
        GROUP BY DATEPART(year, transactionTime),
                 DATEPART(month, transactionTime),
                 DATEPART(day, transactionTime)) a
order by a.year, b.month, c.day

All this particular query does is group all the trades in the Dow30 by date, and sums up the total volume. I use this because the table stores every trade on a per second basis, and I want to roll it up on a per-day basis.

This isn’t the full query, but just an example. I know I could just simply doing this from a single SELECT, but I was wondering if doing a SELECT of a SELECT would incur some sort of performance penalty, or if this all gets optimized magically.

The reason why I formulate the query this way is because that’s how I visualize the query, and I actually join this top-level select with another table, and selecting out the columns from the underlying SELECT makes it easier for me to visualize the query. But having no formal DBA background, I’m not sure if this is wrong, and if I need to figure out a better way of writing my queries.

  • 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-28T03:23:11+00:00Added an answer on May 28, 2026 at 3:23 am

    Nesting SELECTs like this are considered one statement to the optimiser.

    You can see this here: Why use Select Top 100 Percent? and How can I query 'between' numeric data on a not numeric field? In these examples, the nesting here has no effect unless you force it which is generally a bad idea

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

Sidebar

Related Questions

I'm wondering if there's any way to optimize the following SELECT query. (Note: I
I am wondering if there is a way to optimize this query: SELECT Avg(selloff1),
I was wondering if there is any way to SELECT the first number that
I'm wondering why $this->Form->select() in CakePHP 2.1 doesn't come with a wrapping div and
I wondering how can I select columns with specific collation. For example, I want
I was wondering if i could get some help with filtering a select list
I was wondering if this $c = mysql_num_rows(mysql_query(select * from action_6_weekly where code='$code')); is
In the select menu I have various bbcodes. I was wondering how I can
i am wondering why this fails mysql> SELECT Continent C, Name, SurfaceArea -> FROM
I've been wondering if browsers fire any event when select box is dynamicaly populated?

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.