Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to execute the two update queries in phpmyadmin together?

Tags:

php

mysql

Is it possible to execute the two update queries in phpmyadmin together?

Like wise

UPDATE jos_menu SET home = 0 WHERE 1;
UPDATE jos_menu SET home = 1 WHERE id = 9;

Now can we copy both these queries together and Run it on phpmyadmin sql query panel? will it be executed?

like image 860
OM The Eternity Avatar asked Apr 14 '10 13:04

OM The Eternity


2 Answers

Yes, both queries will be executed. The only additional thing you might add is transaction. Thanks to that you'll be sure that both queries executed successful:

START TRANSACTION;
UPDATE jos_menu SET home = 0 WHERE 1;
UPDATE jos_menu SET home = 1 WHERE id = 9;
COMMIT;
like image 54
Crozin Avatar answered Oct 26 '22 06:10

Crozin


update jos_menu set home=case id when 9 then 1 else 0 end

this will update all rows, setting 1 to all that have id=9, and 0 to the rest

like image 27
Alex Avatar answered Oct 26 '22 07:10

Alex