Jump to content

[MySQL] Field Index Unique


safetyweek

Recommended Posts

Hi there, I need your appreciated help.I have this tables in MySQL

/*Navicat MySQL Data TransferSource Server		 : _MySQL_MSource Server Version : 50045Source Host		   : 10.7.4.3:3306Source Database	   : testTarget Server Type	: MYSQLTarget Server Version : 50045File Encoding		 : 65001Date: 2011-04-01 11:53:06*/SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for `_mytabledef`-- ----------------------------DROP TABLE IF EXISTS `_mytabledef`;CREATE TABLE `_mytabledef` (  `xID` int(11) NOT NULL auto_increment,  `_CE` varchar(255) default NULL,  `Name` varchar(255) default NULL,  `DT` date default NULL,  `True` varchar(255) default NULL,  PRIMARY KEY  (`xID`)) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULTCHARSET=latin1;-- ------------------------------ Records of _mytabledef-- ----------------------------INSERT INTO _mytabledef VALUES ('1', '872800000','GUER', '2010-01-31', '0');INSERT INTO _mytabledef VALUES ('2', '863566231','FERR', '2010-02-02', '0');INSERT INTO _mytabledef VALUES ('3', '855797950','AVAL', '2010-03-31', '0');/*Navicat MySQL Data TransferSource Server		 : _MySQL_MSource Server Version : 50045Source Host		   : 10.7.4.3:3306Source Database	   : testTarget Server Type	: MYSQLTarget Server Version : 50045File Encoding		 : 65001Date: 2011-04-01 11:53:17*/SET FOREIGN_KEY_CHECKS=0;-- ------------------------------ Table structure for `_mytabletemp`-- ----------------------------DROP TABLE IF EXISTS `_mytabletemp`;CREATE TABLE `_mytabletemp` (  `xID` int(11) NOT NULL auto_increment,  `_CE` varchar(255) default NULL,  `Name` varchar(255) default NULL,  `DT` varchar(255) default NULL,  PRIMARY KEY  (`xID`)) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULTCHARSET=latin1;-- ------------------------------ Records of _mytabletemp-- ----------------------------INSERT INTO _mytabletemp VALUES ('1', '872800000','GUER', '2011-01-31');INSERT INTO _mytabletemp VALUES ('2', '863566231','FERR', '2011-02-28');INSERT INTO _mytabletemp VALUES ('3', '855797950','AVAL', '2011-03-31');INSERT INTO _mytabletemp VALUES ('4', '855797950','XXXX', '2011-01-03');INSERT INTO _mytabletemp VALUES ('5', '657164259','ZZZZ', '2011-02-03');INSERT INTO _mytabletemp VALUES ('6', '872800000','WWWW', '2011-03-03');INSERT INTO _mytabletemp VALUES ('7', '617869161','YYYY', '2011-03-03');INSERT INTO _mytabletemp VALUES ('8', '863566231','QQQQ', '2011-02-03');

I insert the records of the _mytabletemp in the table _mytabledef.I need this conditions for the copy:1) If `_CE` field value in _mytabledef is = to the `_CE` field value in _mytabletemp, I need save (insert in _mytabledef) the `_CE` field value of _mytabletemp and update where 1 the field `true` of _mytabledef;2) If `_CE` field value in _mytabledef is <to the `_CE` field value in _mytabletemp, I need save (insert in _mytabledef) the `_CE` field value of _mytabletemp;I need the output:

_mytabletempxID	_CE		Name	DT1	872800000	GUER	2011-01-312	863566231	FERR	2011-02-283	855797950	AVAL	2011-03-314	855797950	XXXX	2011-01-035	657164259	ZZZZ	2011-02-036	872800000	WWWW	2011-03-037	617869161	YYYY	2011-03-038	863566231	QQQQ	2011-02-03_mytabledefxID	_CE		Name	DT		True1	872800000	GUER	2010-01-31	12	863566231	FERR	2010-02-28	13	855797950	AVAL	2010-03-31	14	872800000	GUER	2011-01-31	05	863566231	FERR	2011-02-28	06	855797950	AVAL	2011-03-31	07	855797950	XXXX	2011-01-03	08	657164259	ZZZZ	2011-02-03	09	872800000	WWWW	2011-03-03	010	617869161	YYYY	2011-03-03	011	863566231	QQQQ	2011-02-03	0

Can u help me?Thanks in advance-SW

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...