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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:46:02+00:00 2026-06-18T19:46:02+00:00

Could any body tell which query is more efficient if I want to use

  • 0

Could any body tell which query is more efficient if I want to use the new computed columns to filter, aggregate and order data? The one uses nested selection or the one duplicate the expressions in one select clause? Is it database specified?

Query1:

SELECT count(*), (age - 18) AS newcol FROM qmao_person WHERE (age - 18) > 0 GROUP BY (age - 18) ORDER BY (age - 18) DESC;

Query2:

SELECT count(*), s1.newcol FROM
(SELECT (age - 18) AS newcol FROM qmao_person) s1
WHERE s1.newcol > 0 GROUP BY s1.newcol ORDER BY s1.newcol DESC;

BTW, the question is which query will be more efficinent instead of how to optimize the query.

  • 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-06-18T19:46:03+00:00Added an answer on June 18, 2026 at 7:46 pm

    This query will produce identical results and beat both:

    SELECT
        count(*),
        (age - 18) AS newcol
    FROM qmao_person
    WHERE age > 18
    GROUP BY age
    ORDER BY age DESC
    

    But in general, answer to your question is very vendor specific.
    If vendor uses heavy optimization – like factoring out common expressions or converting subselects into joins, it is very possible that results will be identical.

    That said, I would still prefer first query of yours if I could not optimize it like I just did.

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

Sidebar

Related Questions

Could anybody tell me about webservice or any RSS feed which wil return Latitude
Could any body offer me any reason about that? If we do it like
could anybody tell me how can I set a theme for my application which
Could anybody please tell me which is best guide/book/material for socket programming in C?
Could anybody please tell me a shell command for Windows 7 which would take
Could anybody please tell me what's the relation between log4j and apache.commons.logging ? which
Please Any body tell me How to do Captch in Flex? This type of
Could anybody brief about user_token functionality in Auth module? What is a use and
I am new to php and was wondering if anybody could help me with
Could anybody tell me with the pseudo class :active from css only works in

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.