3

I have an SQL statement that returns more than one value: enter image description here

In my code I then need to call the last ID that was inserted. I have seen some examples about SELECT LAST_INSERT_ID() but they all seems to be for insert statements. I just want to show the last inserted id.

So from the image below I would only need to select ID 13.

informatik01
  • 16,038
  • 10
  • 74
  • 104
user123456789
  • 1,914
  • 7
  • 44
  • 100

3 Answers3

4

Use ORDER BY and LIMIT .

Query

SELECT dl.* FROM driver_log dl
WHERE dl.Company_ID = 76 AND dl.Manifesr=tNo = 8199
ORDER BY ID DESC LIMIT 1;

If you want to select only the ID, then use MAX function.

SELECT MAX(dl.ID) as ID 
FROM driver_log dl
WHERE dl.Company_ID = 76 AND dl.Manifesr=tNo = 8199;
Ullas
  • 11,450
  • 4
  • 33
  • 50
2

You can try using the MAX function like

SELECT max(id) FROM driver_log dl
WHERE dl.Company_ID = 76 AND dl.Manifesr=tNo = 8199
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
1

simple way is that Select last row data by query.

SELECT * FROM YourTableName order by ID desc limit 1