How to solve the problem of MySQL left connection
This article introduces the relevant knowledge of "how to solve the left connection problem of MySQL". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Two tables, one user, one user_log
CREATE TABLE `user` (`id` int (11) NOT NULL AUTO_INCREMENT, `name` varchar (20) DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE TABLE `user` (`id` int (10) NOT NULL, `user_ id` int (10) NOT NULL, `log_ time` timestamp NOT NULL DEFAULT '0000-00-0000: 00varchar 0000, `message`varchar (30) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;INSERT INTO `user` VALUES (' 1mm, 'wang') INSERT INTO `user`VALUES ('2clients,' meng'); INSERT INTO `user`VALUES ('3clients,' zhang') -Records of user_log-- INSERT INTO `user_ log` VALUES ('1mm,' 1mm, '2017-07-20 1313 user_ 07mm,' some data') INSERT INTO `user_ log` VALUES ('2mm,' 1mm, '2017-07-27 13 VALUES 13 VALUES,' some data'); INSERT INTO `Log `VALUES ('3 miles,'1 bike, '2017-07-28 13 13 VALUES 07,' some data'); INSERT INTO `Log` VALUES ('4 miles,'1 bike, '2017-08-26 13 VALUES 11 VALUES,' some data') INSERT INTO `user_ log` VALUES ('5mm,' 1mm, '2017-08-26 17 VALUES 11VALUES,' some data'); INSERT INTO `Log 'VALUES (' 6mm, '1mm,' 2017-08-27 13 VALUES 11VALUES, 'some data')
That's it.
SELECT U.N., UL.LOG_TIME, UL.MESSAGE FROM USER U LEFT JOIN USER_LOG UL ON U.ID = UL.USER_ID AND (UL.LOG_TIME > '2017-09-01 07 UL.MESSAGE FROM USER U LEFT JOIN USER_LOG UL ON U.ID 13 UL.MESSAGE FROM USER U LEFT JOIN USER_LOG UL ON U.ID 07' OR UL.LOG_TIME IS NULL) WHERE U.ID = 1
Just put and behind left join on.
This is the end of the content of "how to solve the MySQL left connection problem". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!