Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to UPDATE and SELECT at the same time in MySQL

Tags:

select

mysql

With a relationship with this question How UPDATE and SELECT at the same time and with this code:

UPDATE table SET foo=1 WHERE boo=2

SELECT * from table WHERE foo=1 AND boo=2

How can I UPDATE and SELECT at the same time with MySQL?

It seems the person asking the existing question uses PostgreSQL. How can I do that in MySQL? It seems there is no returning command in MySQL.

like image 711
Netorica Avatar asked May 23 '12 05:05

Netorica


1 Answers

Unfortunately, RETURNING is not supported by MySQL and therefore you need to write separate statements.

As an alternative, you can rely on a stored procedure.

The question of whether MySQL has a returning clause equivalent, in general, was addressed here: Mysql returning clause equivalent

like image 68
wp78de Avatar answered Oct 12 '22 17:10

wp78de