because the date2019-05-08 09:36:14fromtmp2is higher of2019-04-27 14:00:52fromtmp1
and the date2019-05-08 09:36:14fromtmp2is less of2019-05-08 09:39:19fromtmp1
I've tried using MySQL 8.0.17 this query without success
mysql> UPDATE `tmp1` ttt
JOIN (
SELECT
jjj.sName AS jjjsName
FROM
`tmp1` jjj
JOIN `tmp2` kkk ON jjj.sName = kkk.sName
AND kkk.sDate_sHour > jjj.sDate_sHour
WHERE
jjj.sStatus IN ('not registered')
ORDER BY
kkk.sDate_sHour DESC
) AS hhh
SET ttt.sValue = 'N'
WHERE
ttt.sName = hhh.jjjsName;
Query OK, 2 rows affected
this return is wrong
mysql> SELECT
*
FROM
tmp1;
+-----+---------------------+-----------+----------------+--------+
| sID | sDate_sHour | sName | sStatus | sValue |
+-----+---------------------+-----------+----------------+--------+
| 1 | 2019-04-27 14:00:52 | user76681 | not registered | N |
| 2 | 2019-05-08 09:39:19 | user76681 | not registered | N |
+-----+---------------------+-----------+----------------+--------+
2 rows in set
Please can you help me?
Structure tablestmp1andtmp2below
DROPTABLEIFEXISTS`tmp1`;CREATETABLE`tmp1`(`sID` int(11)NOTNULL AUTO_INCREMENT,`sDate_sHour` datetime DEFAULTNULL,`sName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULTNULL,`sStatus` varchar(255)DEFAULTNULL,`sValue` char(1)DEFAULTNULL,PRIMARYKEY(`sID`)) ENGINE=InnoDB AUTO_INCREMENT=3DEFAULT CHARSET=utf8;-- ------------------------------ Records of tmp1-- ----------------------------INSERTINTO`tmp1`VALUES('1','2019-04-27 14:00:52','user76681','not registered',null);INSERTINTO`tmp1`VALUES('2','2019-05-08 09:39:19','user76681','not registered',null);DROPTABLEIFEXISTS`tmp2`;CREATETABLE`tmp2`(`sID` int(11)NOTNULL AUTO_INCREMENT,`sDate_sHour` datetime DEFAULTNULL,`sName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULTNULL,`sStatus` varchar(255)DEFAULTNULL,PRIMARYKEY(`sID`)) ENGINE=InnoDB AUTO_INCREMENT=4DEFAULT CHARSET=utf8;-- ------------------------------ Records of tmp2-- ----------------------------INSERTINTO`tmp2`VALUES('1','2019-05-08 09:36:14','user76681','registered');
Member
49 Points
77 Posts
Update join table using MySQL 8.0.17
May 25, 2020 04:57 PM|Chevy Marl Sunderland|LINK
hi all,
On MySQL database I have two tables
tmp1
And
tmp2
When I've on
tmp2
for the samesName
thesDate_sHour
higher than thesDate_sHour
oftmp1
I need update the columnsValue
withN
valuereturn
tmp1
after updatebecause the date
2019-05-08 09:36:14
fromtmp2
is higher of2019-04-27 14:00:52
fromtmp1
and the date
2019-05-08 09:36:14
fromtmp2
is less of2019-05-08 09:39:19
fromtmp1
I've tried using MySQL 8.0.17 this query without success
this return is wrong
Please can you help me?
Structure tables
tmp1
andtmp2
belowMember
310 Points
76 Posts
Re: Update join table using MySQL 8.0.17
May 26, 2020 12:33 PM|gapimex|LINK
Hi,
Try:
Hope this help