Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

SQL - order by date

Options
  • 10-07-2006 9:17pm
    #1
    Registered Users Posts: 872 ✭✭✭


    Hi,

    i thought this would be easy but its not working out as i need it to

    i have about 10 rows all with a last modified column (datetime) that uses GetDate() to insert the last modified date.

    I want to order by last modified, the most recent being first.

    order by last_modified asc isnt working. its outputting like

    1/7/06
    2/7/06
    3/7/06
    etc.

    when it should be

    3/7/06
    2/7/06
    etc.

    sorting by desc doesnt work either, any ideas ?

    thanks


Comments

  • Registered Users Posts: 1,193 ✭✭✭liamo


    order by last_modified asc isnt working. its outputting like
    1/7/06
    2/7/06
    3/7/06
    etc.
    Pardon my confusion but that is sorted ascending.
    when it should be
    3/7/06
    2/7/06
    No. That's Descending
    sorting by desc doesnt work either
    In what way is it not working?
    any ideas ?
    Yes. Post a real example of a query that doesn't work and the results of the query. Also, it's good practice to post what DBMS you're using - although, in the absence of that information, most people will assume MS SQL Server.

    Regards,

    Liam


  • Closed Accounts Posts: 522 ✭✭✭comer_97


    you don't have the datefield as a varchar do you? that would cause that to happen!


  • Closed Accounts Posts: 22,479 ✭✭✭✭philologos


    use timestamps

    create table date (sqldate TIMESTAMP);
    to create the table in MYSQL anyway

    then when you are inserting data

    insert into date (sqldate) values (NOW()); (I think don't quote me);

    select * from date order by sqldate desc; (orders by timestamp desc)


Advertisement