Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of MySQL left connection

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report