SQL statement order by

Results 1 to 5 of 5

Thread: SQL statement order by

  1. #1
    Join Date
    Dec 1969
    Posts
    538

    Default SQL statement order by

    I can order by number 1,2,3,4, but<BR>I want the reverse 4,3,2,1<BR>What is the SQL statement for this<BR>i have auto indentity as the field<BR>thanks

  2. #2
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: SQL statement order by

    There are two postfixes for the ORDER BY clause, ASC (for ascending) and DESC (for descending). So, do:<BR><BR>SELECT Whatever FROM TableName ORDER BY Field1 DESC<BR><BR>That should do the trick! :)

  3. #3
    Join Date
    Dec 1969
    Posts
    1,019

    Default RE: SQL statement order by

    ORDER BY fieldName DESC

  4. #4
    Jason Buck Guest

    Default RE: SQL statement order by

    You would say this in your SQL statement.<BR><BR>SELECT [auto identity], [another field], [another field1] FROM TABLENAME ORDER BY [auto identity] DESC;<BR><BR>SQL automatically sorts in ascending order. The ORDER BY fieldname DESC; Changes the sort order to DESCending order.<BR><BR>Good luck.<BR><BR>Jason


  5. #5
    Néstor Sulú Guest

    Default RE: SQL statement order by

    You must use DESC<BR><BR>i.e.<BR><BR>"SELECT * FROM MyTable ORDER BY MyFld1 DESC, MyFld2, MyFld3..."<BR><BR>Here, the results will be ordered by MyFld1 in descendent way (4,3,2,1) and MyFld2, MyFld3 in ascendent way (the default, or you can explicit it using ASC).<BR><BR>Both DESC and ASC are SQL ANSI, so they must work in any DBMS.

Posting Permissions

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