3

I have a timestamp field added to every of my records with an SQL timestamp, (yes, the format is actually TIMESTAMP). I want to display my records by date and time; can I just ORDER BY in an SQL statement?

SELECT * FROM table ORDER BY timestamp DESC
TT.
  • 15,774
  • 6
  • 47
  • 88
user1555076
  • 327
  • 2
  • 5
  • 16
  • 6
    Assuming you say *SQL* but really mean **SQL Server**: the `TIMESTAMP` datatype has **nothing** to do with a date and/or a time. But it is a sequentially increasing number (a `ROWVERSION` - that's it's new and more appropriate name), so ordering by it will order by the sequence of changes to the rows. – marc_s Oct 28 '12 at 12:29
  • 2
    Try having a look at this SO question: http://stackoverflow.com/questions/8119386/how-to-convert-sql-servers-timestamp-column-to-datetime-format – SchmitzIT Oct 28 '12 at 12:29
  • 3
    Of course you can: http://sqlfiddle.com/#!12/da966/1 –  Oct 28 '12 at 12:55
  • 1
    This question appears to be off-topic because it has been abandoned without the OP telling us what RDBMS they are using or what problems (if any) they encounter when they try. – Martin Smith Dec 27 '14 at 23:52

2 Answers2

2

Assuming its MySQL,

SELECT *
FROM randomTable
ORDER BY timestampfield DESC;

is just perfect.

Srini V
  • 11,045
  • 14
  • 66
  • 89
0

Yes, I tried it and it is working for me on Oracl SQL Developer