I have two tables:
tbl1:
============================
ID | TOKEN(indexed)
============================
1 | 2176
2 | 2872
3 | 2881
4 | 1182
tbl2:
=======================
ID | TOKEN_REF
=======================
1 | 2
2 | 3
3 | 1
4 | 1
in each iteration the server would receive a 'token', and would update tbl1
if no token exists, in this example token "5241"
would require an insert into tbl1
.
I need to update tbl2
where tbl2.ID
is AUTO_INCREMENTed whenever a token is received (existing or not).
If the token is a new one, first update tbl1
, and only then update tbl2
with the id of the new token.
I was thinking on the INSERT ON EXIST UPDATE, but I don't know how to combine it into a single command.
To summarize:
I need to INSERT ON EXIST UPDATE tbl1
in each iteration and INSERT
the resulting ID
into tbl2
in a single command. is that possible?
ideas?