溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外

發(fā)布時間:2020-06-28 17:54:51 來源:網(wǎng)絡(luò) 閱讀:1983 作者:煢煢木偶 欄目:MySQL數(shù)據(jù)庫

數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外

內(nèi)聯(lián)

數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
SELECT
*
FROM
temployee employees0
INNER JOIN tcustomer customer1 ON ( customer1.id = employees0.id );

左聯(lián)

數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
SELECT
*
FROM
temployee employees0
LEFT OUTER JOIN tcustomer customer1 ON ( customer1.id = employees0.id );

右聯(lián)

數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
SELECT
*
FROM
temployee employees0
RIGHT OUTER JOIN tcustomer customer1 ON ( customer1.id = employees0.id );

全聯(lián)=左聯(lián)+右聯(lián)(MySql不支持)

數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
SELECT * FROM t_employee te FULL JOIN t_customer tc ON (te.id = tc.id);

左外

數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
SELECT
*
FROM
temployee employees0
LEFT OUTER JOIN tcustomer customer1 ON ( customer1.id = employees0.id )
WHERE
customer1_.id IS NULL;

右外

數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
SELECT *
FROM
temployee employees0
RIGHT OUTER JOIN tcustomer customer1 ON ( customer1.id = employees0.id )
WHERE
employees0_.id IS NULL;

全外=左外+右外(MySql不支持)

數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
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;

數(shù)據(jù)庫

Employee
數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外
Customer
數(shù)據(jù)庫左連接、右連接、全聯(lián)接、左外、右外、全外

-- ----------------------------
-- 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, '老張', '設(shè)計部');
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, '老張', '設(shè)計部');
INSERT INTO `t_customer` VALUES (4, '老劉', '人事部');
INSERT INTO `t_customer` VALUES (5, '老黃', '生產(chǎn)部');
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI