SVC Posted January 1, 2008 Share Posted January 1, 2008 Hi, I have an SQL query which selects the last id number in the table and retuns the result to be displayed. I now need to go one stage further and -1 off of the number and the display that. What do i need to include in my SELECT to get the last id number -1 ? Thanks Stephen Link to comment https://forums.phpfreaks.com/topic/84003-select-sql-query/ Share on other sites More sharing options...
Barand Posted January 1, 2008 Share Posted January 1, 2008 SELECT MAX(id) - 1 as maxIdLessOne FROM tablename Link to comment https://forums.phpfreaks.com/topic/84003-select-sql-query/#findComment-427476 Share on other sites More sharing options...
SVC Posted January 1, 2008 Author Share Posted January 1, 2008 hi, i have just tried that and cant get it to work, this is my SELECT that works for the first one, i also have other information being collected from other tables in the same statement. "SELECT * FROM ((properties LEFT JOIN regions ON regions.region_id=properties.region_id) LEFT JOIN countries ON countries.country_id=properties.country_id) LEFT JOIN clients ON clients.client_id=properties.owner_id WHERE status=1 AND approved=1 AND (expiry_date='0000-00-00' OR expiry_date>='$today') ORDER BY property_id DESC LIMIT 1" Link to comment https://forums.phpfreaks.com/topic/84003-select-sql-query/#findComment-427494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.