Coldfusion CS3 - Display most recent record

This isn't too difficult but the syntax errors are bothersome.  I am retrieving the latest record by ID but all the records are displaying.

select * from #vTableName# ORDER BY ID desc

I have tried TOP 1 and MAX but it won't make it through the syntax error.  What would be the correct statement?

Thanks,
John
JohnMac328Asked:
Who is Participating?
 
_agx_Connect With a Mentor Commented:
The syntax is database specific.  TOP is used for MS SQL and Access.  

SELECT TOP 1 *
FROM YourTable
ORDER BY ID DESC

Databases like MySQL use LIMIT

SELECT *
FROM YourTable
ORDER BY ID DESC
LIMIT 1

What database are you using and what is the exact syntax error?
0
 
_agx_Commented:
Though ID numbers can be recycled, so I usually prefer to order by a datetime stamp column.
0
 
JohnMac328Author Commented:
Thanks, I knew I was close but got too frustrated.
0
All Courses

From novice to tech pro — start learning today.