update two tables with one query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

update two tables with one query

Post by Luke »

is it possible to update two tables with one query?

I tried this and it no worky:

Code: Select all

UPDATE `privileges` SET `user_dir` = 'files/',`admin` = '1',`mk_dir` = '1',`del_dir` = '1',`upld_dir` = '1',`dnld_dir` = '1',`ren_dir` = '1',`mk_file` = '1',`upld_file` = '1',`del_file` = '1',`dnld_file` = '1',`view_file` = '1',`ren_file` = '1',`edit_file` = '1' WHERE `user_id` = '2'

AND UPDATE `users` SET `user_name` = 'MC2',`pass_word` = 'cfe6ce19a1f65b98a2daa9d8f772bfbcf8bc71d2' WHERE `user_id` = '2'
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the manual is a wonderous piece of work: http://dev.mysql.com/doc/refman/4.1/en/update.html
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

Yep, just separate each of your update queries with a semicolon.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

that doesn't seem to work with mysql_query()
gives me this error:
error wrote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; UPDATE `users` SET `user_name` = 'Bobby',`pass_word` = 'cfe6ce"
Post Reply