Select Last Record

Hi All!

i’m trying to gest the last record from a table, but a ican get succes. i get the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIMIT 0,11’ at line 7

i’m using this very simple statement:

SELECT
  TicketID
FROM
  ticket
ORDER BY
  TicketID DESC
LIMIT 1

What i’m doing wrong? Help me please!
Thanks in advance.

Re: Select Last Record

Hi,

your select statement is ok …

Set debug mode (application / settings) to yes and try again. You will see many sql statements; one of this generates the error.

Re: Select Last Record

I believe that scriptcase already set limit in the sql too. So, the limit statement will be duplicated.

As you want to display only the last record and do not display the navigate buttons, turn off the the navigation buttons and in the grid configuration change the item “Pagination” to “Total” …

Re: Select Last Record

When you have a numeric value as your primary key defined, and the value of that id column is increased each time a new record is created (for example using auto_increment) and you are interested in the last record created, then you have a few alternatives to load only the last record:


SELECT .......
......
WHERE id = (select max(id) from table)

or:


SELECT boe.id 
FROM `boekingen` boe
WHERE not exists ( select id
          from boekingen boe2
          where boe2.id > boe.id
         )

Likewise you can use a datetime_created/changed column if you have one.