Jump to content
xisto Community
Sign in to follow this  
iGuest

How to update 3 tables in one query in MySql-VB.net MySQL, Multiple Tables

Recommended Posts

How to update 3 tables in one query in MySql-VB.netMySQL, Multiple Tables

To explain deeply my database..Here is it sir..I'm about to create a Computer Aided Instructions systemCREATE TABLE `tbl_maincat` (  `MainCatID` int(11) NOT NULL AUTO_INCREMENT,  (=ID the Identifies the tbl_maincat,do duplication)  `cTitle` varchar(100) DEFAULT NULL, (the FIELD that I'm going to Update)  `cDesc` varchar(100) DEFAULT NULL,  PRIMARY KEY (`MainCatID`)) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=latin1;CREATE TABLE `tbl_subcat` (  `csID` int(11) NOT NULL AUTO_INCREMENT,  `csTitle` varchar(100) DEFAULT NULL,  `csDesc` varchar(100) DEFAULT NULL,  `csCat` varchar(100) DEFAULT NULL, (the FIELD the NEED to be Updated also as I update from tbl_maincat)  `csCatID` varchar(45) DEFAULT NULL,  PRIMARY KEY (`csID`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;Delimiter ;CREATE TABLE `tbl_main` (  `caiID` int(11) NOT NULL AUTO_INCREMENT,  `caiName` varchar(100) DEFAULT NULL,  `MainCat` varchar(100) DEFAULT NULL, (the FIELD the NEED to be Updated also as I update from tbl_maincat)  `SubCat` varchar(100) DEFAULT NULL,  `Desc` varchar(100) DEFAULT NULL,  `caiPath` varchar(255) DEFAULT NULL,  PRIMARY KEY (`caiID`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;for some reasons,those three fields from 3 different table always have a the SAME value, thats why I can also make refference with that fields...My problem with the simple update statement like Update tbl_maincat,tbl_main, tbl_subcat SET tbl_maincat.CTitle ='Hardware',cDesc = 'gfdgfdgdf',  tbl_subcat.CsCat= 'Hardware', tbl_main.MainCat = 'Hardware' WHERE tbl_maincat.MainCatID = '1' and tbl_subcat.CsCat = tbl_maincat.CTitle and tbl_main.MainCat = tbl_maincat.CTitleIs when tables 2 and 3 do not have a value, the UPDATE,do not executes..It seems that ALL THREE TABLES MUST HAVE A VALUE before this UPDATE EXECUTES. I think that the problem with this was in the WHERE clause 'and'. But if I remove the 2 'and' or change it to 'or' then all records will be updated..

-reply by Reymelito A. Lemo

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.