0

Hi all
i have a problem in a task assigned to me in sql 2005

i have table contains column called ID which is an integer
i would to retrieve top 10 rows order by ID in descending order and i want the result of this query to be in ascending order .
when i tried the following query

SELECT * FROM
(
SELECT top 10 * FROM tableX ORDER BY ID DESC
) AS A
ORDER BY A.ID ASC

It gives error and when i searched about it i found that i cant to order by on the data retrieved from a sub query.
I hope any one can solve my problem??

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by tesuji
0

Hi

your select statement is formally quite correct, except for ID which is a well known system identifier of MS SQL server itself.

Because your select statement seems to be only constructed for asking your question it would really be a good idea to post the ORIGINAL erroneous statement AND the ORIGNAL error message too.

-- tesu

Edited by tesuji: n/a

0

try like this....(Just remove AS before tablename A) you will get it.


SELECT * FROM
(
SELECT top 10 * FROM tableX ORDER BY ID DESC
) A
ORDER BY A.ID ASC

0

try like this....(Just remove AS before tablename A) you will get it.


SELECT * FROM
(
SELECT top 10 * FROM tableX ORDER BY ID DESC
) A
ORDER BY A.ID ASC

Both (...) AS A and (...) A is SQL standard 1999/2003 and can't be responsible for his error, unfortunately he hasn't shown the exact select and message by now.

-- tesu

Edited by tesuji: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.