09-08-2017 07:13 AM
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. 🙂
Solved! Go to Solution.
09-08-2017 07:25 AM - edited 09-08-2017 07:26 AM
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.
09-08-2017 07:36 AM
That worked for me thanks so much!
09-08-2017 07:38 AM
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
09-08-2017 07:42 AM
This too worked, brilliant!
09-08-2017 07:47 AM
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