tags:

views:

27

answers:

3

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?

+2  A: 
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

Alexander
Alexander The Great, Its Working.... Thanks , Long Live Alexander...:D
OM The Eternity
+3  A: 

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;
Crozin
Usefull Information.. U know What Now I uderstood Yand How transaction are used.... Thanx Again
OM The Eternity
A: 

If you're not sure if some SQL will break your live site and you don't have a dev server, make a copy of the DB table and test it on that.

CREATE TABLE jos_menu_test LIKE jos_menu;
INSERT jos_menu_test SELECT * FROM jos_menu;
dave1010