Answer the question
In order to leave comments, you need to log in
Is it possible to do SELECT and INSERT in one query?
There are 2 simple requests, is it possible to send them at the same time as one?
Answer the question
In order to leave comments, you need to log in
You can execute a stored procedure and do whatever you want. or to make within one transaction - two scripts.
BEGIN
SAVEPOINT bak_trn; -- опционально
SELECT FROM ... ;
INSERT INTO ... ;
EXCEPTION -- опционально
WHEN OTHERS THEN
ROLLBACK TO bak_trn;
RAISE;
END;
COMMIT;
Example 1
UPDATE
Table_A
SET
Table_A.token = CONCAT_WS(':', Table_B.category_id, Table_B.form_id, Table_B.mark_id, Table_B.model_id)
FROM
tbl_category_mark_model_form Table_A
INNER JOIN
tbl_category_mark_model_form Table_B
ON
Table_A.id = Table_B.id
;
Example 2
UPDATE tbl_category_mark_model_form AS tbl_1
INNER JOIN(
SELECT * FROM tbl_category_mark_model_form
) AS tbl_2 ON tbl_1.id = tbl_2.id
SET tbl_1.token = CONCAT_WS(':', tbl_2.category_id, tbl_2.form_id, tbl_2.mark_id )
;
other examples:docs.mirocow.com/doku.php?id=sql:mysql:update-someself
in MS SQL there is Output
returns the rows, including the assigned IDs and guides ;)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question