By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,441 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

Updating 3 tables in one query without using stored proc

P: 6
hello everyone..i have 3 tables t1,t2,t3..if i update t1,t2 and t3 must also be could i do this? i have just been tried
Expand|Select|Wrap|Line Numbers
  1. UPDATE t1,t2,t3 SET t1.f1='sample',t2.f1='sample',t3.f1='sample' WHERE t1.f1='test' and t2.f1='test' and t1.f1='test' 
using this,update fails if t2 and t3 could not find 'test' in their fields,if i use OR all records will be..

i have also tried JOINS
Expand|Select|Wrap|Line Numbers
  1. Update tbl_maincat AS m LEFT JOIN tbl_maincat AS m2 ON m.cTitle = m2.cTitle,
  2. tbl_main AS c LEFT JOIN tbl_main AS c2 ON c.MainCat = c2.Maincat,
  3. tbl_subcat AS s LEFT JOIN tbl_subcat AS s2 ON s.csCat = s2.csCat
  4. SET
  5. m.cTitle = 'Hardware25',
  6. m.cDesc = 'H2desc',
  7. c.MainCat = 'Hardware25',
  8. s.csCat = 'Hardware25'
  9. WHERE
  10. m.MainCatID=29 and
  11. c.Maincat='Hardware23' and
  12. s.csCat='Hardware23';
same...because of the AND operator...

if multiple query solved this..please let me know the proper construction in

please everyone..its bugging me for almost a month..
im a newbie and mysql programmer..
Jul 1 '10 #1
Share this Question
Share on Google+
1 Reply

P: 142
What about Trigger..?
Jul 7 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.