jaymc Posted October 2, 2007 Share Posted October 2, 2007 Is it possible to update numerous tables in the same query, e.g UPDATE `tab1`, `tab2` SET tab1.minutes = '60', tab2.hours = '4' Probably not the syntax, but can it be done rather than using 2 seperate update queries. If so, is it more optimal? Quote Link to comment Share on other sites More sharing options...
hemlata Posted October 2, 2007 Share Posted October 2, 2007 Hello, Yes, i think it can be done. i tried a simple script on two tables and it run successfully UPDATE table1 AS t1, table2 AS t2 SET t1.field1 = 'test1', t2.field2 = 'test2'; Regards, Quote Link to comment Share on other sites More sharing options...
jaymc Posted October 2, 2007 Author Share Posted October 2, 2007 Nice Would this improve performance, even if its slight? Assuming Im not closing and opening the mysql connection after every query Or is it simple a neater way of updating multiple tables in the same script Quote Link to comment Share on other sites More sharing options...
fenway Posted October 2, 2007 Share Posted October 2, 2007 Nice Would this improve performance, even if its slight? Assuming Im not closing and opening the mysql connection after every query Or is it simple a neater way of updating multiple tables in the same script Again with the performance, eh? It's not meant to update multiple tables in the same script... it's meant for updates that require joining multiple tables to produce the result. Quote Link to comment Share on other sites More sharing options...
jaymc Posted October 2, 2007 Author Share Posted October 2, 2007 Would I be better just sticking to one query per update then? Quote Link to comment Share on other sites More sharing options...
fenway Posted October 2, 2007 Share Posted October 2, 2007 Would I be better just sticking to one query per update then? Yes, unless you need info from another table. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.