order by ??

  • I have table like this

    col1 col2 col3

    5 3 8

    6 2 9

    7 1 10

    and i want result as

    col1 col2 col3

    5 1 8

    6 2 9

    7 3 10

    ie, col2 also in ascending order.

    What is the query..?

    Order by col1 asc,col2 asc, col3 asc is not working..please check

  • What are the data types of these columns? Also, could you be more specific than "it isn't working"?

    Jim

  • your example's messing you up... a row of data is just that: each element is related to the others. grabbing a value from another row? why?

    if you substitute names for your numbers, you'll see why it doesn't seem right:

    col1 col2 col3

    George Washington Virginia --5 3 8

    Abraham Lincoln Illinois --6 2 9

    Bill Clinton Arkansas -- 7 1 10

    would you really want:

    col1 col2 col3

    George Clinton Virginia --5 1 8

    Abraham Lincoln Illinois --6 2 9

    Bill Washington Arkansas --7 3 10

    show us the REAL code(not the pseudo code you tried to show as an example) so we can really help you.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • SELECT

    tCOL1COL3.COL1 AS COL1,

    tCOL2.COL2 AS COL2,

    tCOL1COL3.COL3 AS COL3

    FROM

    (

    SELECT

    COL1,

    COL3,

    RANK () OVER(ORDER BY COL1 ASC) AS ROWNUMBER

    FROM

    SQLSerC /* YOUR TABLE HAVING COLUMNS COL1 (INT), COL2(INT), COL3(INT) */

    )tCOL1COL3

    INNER JOIN

    (

    SELECT

    COL2,

    RANK () OVER(ORDER BY COL2) AS ROWNUMBER

    FROM

    SQLSerC /* YOUR TABLE HAVING COLUMNS COL1 (INT), COL2(INT), COL3(INT) */

    )tCOL2

    ON

    tCOL1COL3.ROWNUMBER = tCOL2.ROWNUMBER

    Sample Run Results ...

    RunStatusCOL1COL2COL3

    Before Run ... 538

    Before Run ... 629

    Before Run ... 7110

    RunStatusCOL1COL2COL3

    After Run ...518

    After Run ...629

    After Run ...7310

  • Thank you Amartha dutta

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply