- left join:查询出左边表所有数据,右边表匹配就查询,没有就是null
- inner join: 查询出公共数据
- right join:查询右边表所有数据,左边为空就查询。
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for detail_info
-- ----------------------------
DROP TABLE IF EXISTS `detail_info`;
CREATE TABLE `detail_info` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`user_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
-- ----------------------------
-- Records of detail_info
-- ----------------------------
BEGIN;
INSERT INTO `detail_info` VALUES (1, '哈哈', '2'), (2, '李光洙', '1');
COMMIT;
-- ----------------------------
-- Table structure for user_info
-- ----------------------------
DROP TABLE IF EXISTS `user_info`;
CREATE TABLE `user_info` (
`id` bigint(0) NOT NULL,
`user_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`age` int(0) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
-- ----------------------------
-- Records of user_info
-- ----------------------------
BEGIN;
INSERT INTO `user_info` VALUES (1, '李光洙', 11), (2, '宋智孝', 22), (3, '王鼻子', 88);
COMMIT;
detail_info
user_info
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1d2d130ac561786c8841abf3051c145e.png)
LEFT JOIN![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b895e3ce33cf70ef4a2dcc13e4850b02.png)
INNER JOIN![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9d0bce8220bf57178fdd46469ebab68c.png)
RIGHT JOIN