数据库左连接、右连接、全联接、左外、右外、全外
成都创新互联公司服务项目包括元宝网站建设、元宝网站制作、元宝网页制作以及元宝网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,元宝网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到元宝省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
内联
SELECT
*
FROM
temployee employees0
INNER JOIN tcustomer customer1 ON ( customer1.id = employees0.id );
左联
SELECT
*
FROM
temployee employees0
LEFT OUTER JOIN tcustomer customer1 ON ( customer1.id = employees0.id );
右联
SELECT
*
FROM
temployee employees0
RIGHT OUTER JOIN tcustomer customer1 ON ( customer1.id = employees0.id );
全联=左联+右联(MySQL不支持)
SELECT * FROM t_employee te FULL JOIN t_customer tc ON (te.id = tc.id);
左外
SELECT
*
FROM
temployee employees0
LEFT OUTER JOIN tcustomer customer1 ON ( customer1.id = employees0.id )
WHERE
customer1_.id IS NULL;
右外
SELECT *
FROM
temployee employees0
RIGHT OUTER JOIN tcustomer customer1 ON ( customer1.id = employees0.id )
WHERE
employees0_.id IS NULL;
全外=左外+右外(MySql不支持)
SELECT *
FROM
t_employee te
FULL JOIN t_customer tc ON ( te.id = tc.id )
WHERE
te.id IS NULL
OR tc.id IS NULL;
数据库
Employee
Customer
-- ----------------------------
-- Table structure for t_employee
-- ----------------------------
DROP TABLE IF EXISTS `t_employee`;
CREATE TABLE `t_employee` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`employee_name` varchar(255) DEFAULT NULL,
`employee_part` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- ----------------------------
-- Records of t_employee
-- ----------------------------
INSERT INTO `t_employee` VALUES (1, '老潘', '总裁部');
INSERT INTO `t_employee` VALUES (2, '老王', '秘书部');
INSERT INTO `t_employee` VALUES (3, '老张', '设计部');
INSERT INTO `t_employee` VALUES (4, '老李', '运营部');
-- ----------------------------
-- Table structure for t_customer
-- ----------------------------
DROP TABLE IF EXISTS `t_customer`;
CREATE TABLE `t_customer` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`customer_name` varchar(255) DEFAULT NULL,
`customer_part` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- ----------------------------
-- Records of t_customer
-- ----------------------------
INSERT INTO `t_customer` VALUES (2, '老王', '秘书部');
INSERT INTO `t_customer` VALUES (3, '老张', '设计部');
INSERT INTO `t_customer` VALUES (4, '老刘', '人事部');
INSERT INTO `t_customer` VALUES (5, '老黄', '生产部');
文章名称:数据库左连接、右连接、全联接、左外、右外、全外
标题来源:http://myzitong.com/article/gghpec.html