Shahzeb Akram Shahzeb Akram - 6 months ago 16
MySQL Question

Error while using LAST() aggregate function in SQL

Recently i started working on a project. In which i want to fetch the last record inserted in the database.

Query is:

SELECT c.lat, c.lng, LAST(v.count)
FROM camera_camera c , camera_cameravehiclecount v
WHERE c.id = v.cameraid


I am using the
LAST()
aggregate function but i am getting this error:


1064 - 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 '(v.count) from camera_camera c , camera_cameravehiclecount v
WHERE c.id = v.came' at line 1


I cross checked the syntax from w3school but still i am getting this error. I am using DB4free as my online database. Kindly tell me where i am doing mistake.

Answer

The w3 page suggests a workaround, since LAST isnt in mysql. http://www.w3schools.com/sql/sql_func_last.asp

You can try this to get the same thing:

SELECT c.lat, c.lng, v.count
FROM camera_camera c , camera_cameravehiclecount v 
WHERE c.id = v.cameraid 
ORDER BY v.count DESC 
LIMIT 1
Comments