Results 1 to 4 of 4

Thread: SQL Order By

  1. #1
    Join Date
    Dec 2015
    Posts
    3

    Unanswered: SQL Order By

    I have a SQL statement which selects specific data from my database, I would like to add an ORDER BY statement to sort the final column in ascending order.
    Code:
     AND DATEDIFF(end_date, CURDATE()) < 31
    Code:
     SELECT  Supplier_Details_tbl.Supplier_Name,
            Documents_tbl.Document_Type,
            Documents_tbl.Start_Date,
            Documents_tbl.End_Date,
            Documents_tbl.Tarrif_Name,
            House_details_tbl.House_Name,
            DATEDIFF(end_date, CURDATE())
    FROM    HDMS.House_Details_tbl AS House_details_tbl,
            HDMS.Documents_tbl AS Documents_tbl,
            HDMS.Supplier_Details_tbl AS Supplier_Details_tbl
    WHERE   House_details_tbl.ID = Documents_tbl.Supplier_Address
            AND Supplier_Details_tbl.ID = Documents_tbl.Supplier_ID
            AND Documents_tbl.R_Sent = 0
            AND Documents_tbl.Superceed = 0
            AND DATEDIFF(end_date, CURDATE()) < 31
    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so what is stopping you adding an ORDER BY clause ?
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Dec 2015
    Posts
    3

    Order By

    Quote Originally Posted by healdem View Post
    so what is stopping you adding an ORDER BY clause ?
    I don't know where to add it or how to add it to a calculation

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    https://uk.search.yahoo.com/yhs/sear...mysql+order+by

    ORDER BY goes at the end of the SQL statement
    you can specify more than one column in an ORDER
    you can specify whether a column should be in ASCending or DESCending order, those terms could be mixed
    eg:-
    Code:
    ORDER by aCol ASC, bCol DESC, cCol ASC
    the column(s) in an ORDER BY clause do not need to be in the list of columns int he SELECT clause
    Last edited by healdem; 12-22-15 at 15:02.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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