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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:56:00+00:00 2026-05-27T18:56:00+00:00

I am facing a strange error in SQL Server and I want some explanation

  • 0

I am facing a strange error in SQL Server and I want some explanation of it.

When I write ORDER BY in a subquery, for instance

SELECT a FROM (SELECT * FROM A ORDER BY a) T

it throws the following error

The ORDER BY clause is invalid in views, inline functions, derived
tables, subqueries, and common table expressions, unless TOP or FOR
XML is also specified.

But when I use TOP in subquery it works normally

 SELECT a 
 FROM
    (SELECT TOP 1000000 * FROM A ORDER BY a) T

So, does it mean that I can select top row count of A, instead of

SELECT a FROM (SELECT * FROM A ORDER BY a) T

In that case. what is the reason of error?

  • 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-27T18:56:01+00:00Added an answer on May 27, 2026 at 6:56 pm

    There is no much sense to sort the subquery and after that select something from it – it is not guaranteed that top-level select will be ordered, so – there is no sense to order the inner query

    But if you order inner query with TOP statement – it also not guaranteed that top level select will be ordered in such a way, but it will contain only top X rows from the inner query – that is already makes sense.

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

Sidebar

Related Questions

Im facing a strange issue trying to move from sql server to oracle. in
We are facing a strange performance problem with SQL Server Express 2005 in a
I'm facing strange error. I use Glassfish 3.1.1 withn jdk7 and since some time
I'm facing a rather strange Issue when trying to load data from an XML-Webservice.
I am facing a strange FlexUnit Error: Whoa... been asked to send another complete
I am facing a strange javascript object expected error in IE8? On IE Developer
I am facing a strange error in cakephp2.0. I have created two layouts -
Right now I'm facing some kind of strange problem with a Weblogic domain. When
I am facing strange issue. I have wep-part that reads data from user's profile.
I'm facing a strange problem when deploying my application to the production server. I've

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.