Results 1 to 10 of 10

Thread: Query

  1. #1
    Join Date
    Sep 2002
    Posts
    7

    Unanswered: 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.ElayaRaja

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    without using an ORDER BY? why not? that's the only way


    rudy

  3. #3
    Join Date
    Oct 2002
    Posts
    369

    Post Re: Query

    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

  4. #4
    Join Date
    Oct 2002
    Posts
    369

    Post Re: Query

    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.

  5. #5
    Join Date
    Sep 2002
    Posts
    7
    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

  6. #6
    Join Date
    Jul 2002
    Posts
    229
    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?

  7. #7
    Join Date
    Oct 2002
    Posts
    369
    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.

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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

  9. #9
    Join Date
    Oct 2002
    Posts
    369
    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?)

  10. #10
    Join Date
    Sep 2002
    Posts
    7
    Hello friends!

    Thanks for answering me. Ur solutions are really useful.

    Thanks & Regards
    E.ElayaRaja

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •