I was playing in a MySQL database and wanted to only view the record that had second to last of table but did not get any row the query is given below
What is the problem of my query
SELECT * FROM table WHERE id='(LAST_INSERT_ID()-1)'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
LAST_INSERT_ID()-1has no guarantee of pointing at an actual record. Try:SELECT * FROM table ORDER BY id DESC LIMIT 1,1Ideally you should be using something other than id to determine the age of a record, preferably a timestamp.