Wednesday, March 28, 2012

Query

Hello friends!

I have a row like this

Select * from SalMax

Sid Sname Salary
---- ------- ---------
1 Raja 3000.0
2 Vasu 7000.0
5 Siva 1700.0
6 Viswa 10700.0
3 Prabu 5000.0
4 Vikram 9000.0
9 Sachin 10000.0
15 Dravid 14000.0

The Output I want is just the Reverse without using Order by any column

the Output I want is
15 Dravid 14000.0
9 Sachin 10000.0
4 Vikram 9000.0
3 Prabu 5000.0
6 Viswa 10700.0
5 Siva 1700.0
2 Vasu 7000.0
1 Raja 3000.0

Thanks & Regards
E.ElayaRajawithout using an ORDER BY? why not? that's the only way

rudy|||Originally posted by ThankuGod
Hello friends!

I have a row like this

Select * from SalMax

Sid Sname Salary
---- ------- ---------
1 Raja 3000.0
2 Vasu 7000.0
5 Siva 1700.0
6 Viswa 10700.0
3 Prabu 5000.0
4 Vikram 9000.0
9 Sachin 10000.0
15 Dravid 14000.0

The Output I want is just the Reverse without using Order by any column

the Output I want is
15 Dravid 14000.0
9 Sachin 10000.0
4 Vikram 9000.0
3 Prabu 5000.0
6 Viswa 10700.0
5 Siva 1700.0
2 Vasu 7000.0
1 Raja 3000.0

Thanks & Regards
E.ElayaRaja|||RE: Hello friends!

I have a row like this

Select * from SalMax
Sid Sname Salary
---- ------- ---------
1 Raja 3000.0
2 Vasu 7000.0
The Output I want is just the Reverse without using Order by any column
the Output I want is
15 Dravid 14000.0
9 Sachin 10000.0
Thanks & Regards E.ElayaRaja

Q1 The Output I want is [descending Salary] without using Order by
A1 Create a clustered descending index on Salary.|||My Question is not answered. I think u didnt undestand my question.
I repeat

I have a row like this

Select * from SalMax

Sid Sname Salary
---- ------- ---------
7 Raja 3000.0
2 Vasu 7000.0
5 Siva 1700.0
15 Dravid 14000.0

The Output I want is just the Reverse without using Order by any column

the Output I want is
15 Dravid 14000.0
5 Siva 1700.0
2 Vasu 7000.0
7 Raja 3000.0

I just want the reverse of the query .

Thanks & Regards
E.ElayaRaja|||Do you mean that you first run a query which results in a set of records, returned in no particular order at all - then, you would like to get that very same set of records just displayed in the reverse order?

May I ask what the problem behind is?

I guess you could select the records into a temporary table, to which you then add the clustered descending index?|||RE: My Question is not answered. I think u didnt undestand my question...
I just want the reverse of the query . Thanks & Regards E.ElayaRaja

Q1 [I think u didnt undestand my question]?
A1 True I did not, that was why it was restated and paraphrased.

Q2 [Given a set of arbitrary query results, (returned in no particular order): How would may one get that very same set of records returned in the reverse order, (BUT) without using ORDER BY?]

A2 The Coolberg post correctly alluded to the answer of Q2. Insert the result set into a work table with an additional autoincrementing identity column. Then alter the work table to make the additional identity column clustered and descending. Finally, a select from the work table of all columns (except the additional identity column) should return the very same set of records, in the reverse order.|||Insert the result set into a work table with an additional autoincrementing identity column. Then alter the work table to make the additional identity column clustered and descending. Finally, a select from the work table of all columns (except the additional identity column) should return the very same set of records, in the reverse order.

maybe it's me but the performance of the above strategy is going to be a lot worse than ORDER BY

what the heck is wrong with using ORDER BY anyway?

rudy|||RE: quote:
------------------------
Insert the result set into a work table with an additional autoincrementing identity column. Then alter the work table to make the additional identity column clustered and descending. Finally, a select from the work table of all columns (except the additional identity column) should return the very same set of records, in the reverse order.
------------------------
maybe it's me but the performance of the above strategy is going to be a lot worse than ORDER BY
what the heck is wrong with using ORDER BY anyway? rudy

Q1 [What the heck is wrong with using ORDER BY anyway?]
A1 The question being addressed excluded using ORDER BY [Given a set of arbitrary query results, (returned in no particular order): How would may one get that very same set of records returned in the reverse order without using ORDER BY?]

Q2 [Maybe it's me but the performance of the above strategy is going to be a lot worse than ORDER BY?]
A2 Not you, but rather the DBMS / query engine. I would expect avoiding using ORDER BY as a general practice to be a rather expensive endevour. (Perhaps the exclusion is related to some sort of performance testing?)|||Hello friends!

Thanks for answering me. Ur solutions are really useful.

Thanks & Regards
E.ElayaRaja

No comments:

Post a Comment