Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2004
    Location
    Maryland
    Posts
    152

    Post Unanswered: Sorting Situation

    Hi,

    I am trying to get data as it is available in the table but every time I run sql statement it shows in asending order. How can I avoid this asending order situation?

    Select distinct db_contract,title1 from titles where db_contract=39624
    db_contract Title1
    39624 HIGHWAY
    39624 M-24-001
    39624 M-24-002
    39624 R-24-003
    39624 M-24-006
    39624 Z-24-007

    Any help will be appreciated.
    mr_roomi

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Why should that be a problem ... most probably you have an index on the columns
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  3. #3
    Join Date
    Apr 2003
    Location
    Washington DC area
    Posts
    1,770

    Wink sorting situation

    Simple, sort\index before you execute the statement. Pick the field you want.

  4. #4
    Join Date
    Mar 2004
    Location
    Maryland
    Posts
    152

    Sorting Situation

    No, I don't have index on that field....
    mr_roomi

  5. #5
    Join Date
    Mar 2004
    Location
    Maryland
    Posts
    152

    table structure

    here is table strucure

    title_id int (type identity)
    db_contract decimal
    title1 varchar
    mr_roomi

  6. #6
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Select distinct db_contract,title1 from titles where db_contract=39624 order by title_id
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  7. #7
    Join Date
    May 2004
    Posts
    1
    Try removing the Distinct as the resultant order will be dependant on that last operation in the query plan, why does the order matter to you? If you want it in a particular order use the order by clause...

    Hope that helps

  8. #8
    Join Date
    Mar 2004
    Location
    Maryland
    Posts
    152

    Sorting Situation

    Hi,

    I applied that query it gave me this error:

    Server: Msg 145, Level 15, State 1, Line 1
    ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

    Then i inserted title_id in query and it gave me this result and title1 is still repeating but i want title only once and in the same order it is in table:

    220430 HIGHWAY
    220431 HIGHWAY
    220432 M-24-001
    220433 M-24-007
    220434 M-24-003
    220435 HIGHWAY
    220436 HIGHWAY
    220437 HIGHWAY
    220438 M-24-001
    220439 M-24-002
    220440 HIGHWAY
    220441 HIGHWAY
    220442 HIGHWAY
    220443 M-24-001
    220444 M-24-007
    220445 HIGHWAY
    220446 M-24-002
    220447 HIGHWAY
    220648 M-24-007
    220649 HIGHWAY
    220650 M-24-007
    mr_roomi

Posting Permissions

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