get last row id in pymysql - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: get last row id in pymysql (/thread-5285.html) |
get last row id in pymysql - tony1812 - Sep-26-2017 Hello, I am pretty new to python I am wondering is this is the correct syntax to get the last row id in a my=sql mysql table? cur=conn.cursor() sql="SELECT row_id FROM test_tb ORDER BY row_id DESC LIMIT 1" cur.execute(sql) last_id = cur.fetchone() for lastID in last_id: print(lastID)Thanks. RE: get last row id in pymysql - Larz60+ - Sep-26-2017 You can do it with your query: SELECT * FROM Table ORDER BY ID DESC LIMIT 1you have it (almost) right, so there will only be one row, and it's the one you want. |