Hi
I have a table in mysql database, with 3 columns: id | title | description .
The id column is INT AUTO_INCREMENT .
Does anyone know how to select the last two inserted rows, with the latest inserted IDs?
Select the last inserted rows, latest IDs
-
- Posts: 107
Select the last inserted rows, latest IDs
Admin
Posts: 805
Hi,
Use these instructions in the SELECT query: ORDER BY ID DESC and LIMIT.
- ORDER BY ID DESC - will sort your records in descending order, according to the id.
- LIMIT 2 - will return you two (and the first two) records.
Use these instructions in the SELECT query: ORDER BY ID DESC and LIMIT.
Code: Select all
SELECT * FROM table ORDER BY id DESC LIMIT 2
- LIMIT 2 - will return you two (and the first two) records.
sandy
Posts: 3
Hi,
If you're using PDO, use PDO::lastInsertId();// To Display the last Inserted value
If you're using MySql, use mysql_insert_id();// To Display the last Inserted value
Thanks
Edit:
- These work after an INSERT query is performed.
If you're using PDO, use PDO::lastInsertId();// To Display the last Inserted value
If you're using MySql, use mysql_insert_id();// To Display the last Inserted value
Thanks
Edit:
- These work after an INSERT query is performed.
Similar Topics
-
Multiple select for upload not working on mobile
JavaScript - jQuery - Ajax
First post
Plessant Coursesweb,Last post
meight useless to ask but it seems this upload for picture-album is not working on my mobile-page
but on my computer I just...
Try to search on the internet for:
html multiple select upload mobile