Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. MySQL
  4. How to update 3 tables simultaneously...

How to update 3 tables simultaneously...

Scheduled Pinned Locked Moved MySQL
csharpdatabasemysqltutorial
4 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reymelito A Lemo
    wrote on last edited by
    #1

    hello everyone..i have 3 tables t1,t2,t3..if i update t1,t2 and t3 must also be updated..how could i do this? i have just been tried [CODE]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' [/CODE] 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 [CODE] Update tbl_maincat AS m LEFT JOIN tbl_maincat AS m2 ON m.cTitle = m2.cTitle, tbl_main AS c LEFT JOIN tbl_main AS c2 ON c.MainCat = c2.Maincat, tbl_subcat AS s LEFT JOIN tbl_subcat AS s2 ON s.csCat = s2.csCat SET m.cTitle = 'Hardware25', m.cDesc = 'H2desc', c.MainCat = 'Hardware25', s.csCat = 'Hardware25' WHERE m.MainCatID=29 and c.Maincat='Hardware23' and s.csCat='Hardware23';[/CODE] same...because of the AND operator... if multiple query solved this..please let me know the proper construction in VB.net.. please everyone..its bugging me for almost a month.. im a newbie vb.net and mysql programmer.. thanks..

    ...i am dying to learn PLs and DBs...

    C 1 Reply Last reply
    0
    • R Reymelito A Lemo

      hello everyone..i have 3 tables t1,t2,t3..if i update t1,t2 and t3 must also be updated..how could i do this? i have just been tried [CODE]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' [/CODE] 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 [CODE] Update tbl_maincat AS m LEFT JOIN tbl_maincat AS m2 ON m.cTitle = m2.cTitle, tbl_main AS c LEFT JOIN tbl_main AS c2 ON c.MainCat = c2.Maincat, tbl_subcat AS s LEFT JOIN tbl_subcat AS s2 ON s.csCat = s2.csCat SET m.cTitle = 'Hardware25', m.cDesc = 'H2desc', c.MainCat = 'Hardware25', s.csCat = 'Hardware25' WHERE m.MainCatID=29 and c.Maincat='Hardware23' and s.csCat='Hardware23';[/CODE] same...because of the AND operator... if multiple query solved this..please let me know the proper construction in VB.net.. please everyone..its bugging me for almost a month.. im a newbie vb.net and mysql programmer.. thanks..

      ...i am dying to learn PLs and DBs...

      C Offline
      C Offline
      CitrusTech
      wrote on last edited by
      #2

      I'd be very reluctant to do this as a single query on a join. My preference would be to use a transaction on mutiple updates (Transactions and Atomic Operations).

      Data Quality Tools

      R 1 Reply Last reply
      0
      • C CitrusTech

        I'd be very reluctant to do this as a single query on a join. My preference would be to use a transaction on mutiple updates (Transactions and Atomic Operations).

        Data Quality Tools

        R Offline
        R Offline
        Reymelito A Lemo
        wrote on last edited by
        #3

        thank you sir,,but im a newbie mysql user..please give me a example of updating 3 tables..i have searched it thoroughly in google but all of their examples just resides in 2 tables....please?

        C 1 Reply Last reply
        0
        • R Reymelito A Lemo

          thank you sir,,but im a newbie mysql user..please give me a example of updating 3 tables..i have searched it thoroughly in google but all of their examples just resides in 2 tables....please?

          C Offline
          C Offline
          CitrusTech
          wrote on last edited by
          #4

          Reymelito If you have an example of an update on two tables I'd be interested in seeing it. Let me have the example or link and I'll have a proper pop at this. From http://dev.mysql.com/doc/refman/5.1/en/subquery-restrictions.html: >>In general, you cannot modify a table and select from the same table in a subquery Which rules out one option... My preferred appoach would still be transactions since it will be much more maintainable/readable. Here's an old thread on that http://www.codeguru.com/forum/showthread.php?t=371117&highlight=auto-commit Cheers Dave

          Data Quality Tools

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups