Hi all,
I'm new to Labview & MySQL actually learning it on the job. Please forgive me if it's a basic, silly question.
So I need to design a project that will update an existing DB in MySQL. The data is dynamic and must update every time a part goes through a machine.
I have this done and I am connecting to the Db and information is going in. The part I'm stuck on is the autogenerated index key in MYSQL. I need to read back the last key generated in the DB to labview for other parts of the project.
So how can I generate the last key back, here's what I have so far. Thanks so much in advance. 🙂
已解决! 转到解答。
Hi,
if the new key is defined as latest key+1 you could simply try something like
select MAX(Index_Key) from ...
else you could sort your select descending by creation timestamp and use the first return value.
That worked for me thanks so much!
If you table design includes an auto-index column you could use the SQL-command
SELECT LAST_INSERT_ID();
to get the last auto-index id that you have created.
Greetings, Jens
This too worked, brilliant!
Bear in mind that both solutions can yield different results if more than one database user writes to the same table. My solution will give back the auto-index that your connection created (regardless of the table) while crabman's solution will give back the max-index of from one specific table. So if another user inserts data into the same table directly after your insert command you don't get back the index-id of your insert command.
Jens