Search code examples
sqlselectderby

SQL Apache Derby - Select last value in column


I am using Apache Derby and am trying to select the last value in a column.

Currently I have the following:

SELECT id FROM hotels ORDER BY id DESC WHERE ROWNUM <=1;

However this is resulting in a syntax error:

Syntax error: Encountered "WHERE" at line 1, column 44.

Would anyone know the proper way to write this query?

Thank you.


Solution

  • The order by clause goes after the where. Perhaps you intend:

    SELECT MAX(id)
    FROM hotels;