If I run an insert request but it fails due to a duplicate key error, is there a way to get my primary key without making another choice?
Basically:
INSERT INTO tbl (field) VALUES ('myvalue')
This fails because there is already a record with identifier: 1 and field: myvalue.
Now I want to know that ID: 1 without making another request:
SELECT id FROM tbl WHERE field = 'myvalue'
is it possible?
source
share