0

I am using Ultralite 12. I have a table with a date field called "Date." (I didn't name it.) I want to sort my results by this field.

The query:

SELECT * FROM ItemHistory
where itemid = 'BC-2000-005' and customerid = '227B05'

works and returns the results

HistoryType,ItemID,UM_ID,CustomerID,Date,OrderHeaderID
1,'BC-2000-005',1,'227B05',2014-11-24,'849446-1'
1,'BC-2000-005',1,'227B05',2014-12-17,'852747-1'
1,'BC-2000-005',1,'227B05',2015-01-02,'854701-1'
1,'BC-2000-005',1,'227B05',2015-02-09,'859811-1'

I want to return the top answer when the results are sorted by date (in other words, the last one).

SELECT top 1 * FROM ItemHistory
where itemid = 'BC-2000-005' and customerid = '227B05'
order by date DESC

gives me a syntax error by DESC. I've tried this as well:

SELECT top 1 * FROM ItemHistory
where itemid = 'BC-2000-005' and customerid = '227B05'
order by [date] DESC
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
TychaBrahe
  • 55
  • 6

1 Answers1

0

Try with "date". You could find more info from http://dev.cs.uni-magdeburg.de/db/sybase9/help/dbrfen9/00000010.htm

Sergey Gazaryan
  • 1,013
  • 1
  • 9
  • 25
  • Do you want to emphasize that enclosing the column name in double quotes is the standard SQL way to indicate a 'delimited identifier', and a delimited identifier is the standard way of using a reserved word such as `date` as a column name (or table name, or …)? – Jonathan Leffler Jul 30 '15 at 21:40
  • In case of MySql it is ՝ . Im not that there is a standard. – Sergey Gazaryan Jul 30 '15 at 21:48
  • 1
    There's a standard: double quotes. There are abuses of the standard: just about every DBMS does that to some extent or another, except perhaps DB2. See [What does the SQL standard say about usage of backtick](http://stackoverflow.com/questions/10573922/), probably amongst other questions. – Jonathan Leffler Jul 30 '15 at 21:51