mysql 左连接、右连接和内连接_MySQL
程序员文章站
2023-12-30 20:39:40
...
bitsCN.com
脚本如下:
drop table table1;
CREATE TABLE `andrew`.`table1`
(
`name` VARCHAR(32) NOT NULL,
`city` VARCHAR(32) NOT NULL
)
ENGINE = MyISAM;
insert into TABLE1(name, city) values ('Person A', 'BJ');
insert into TABLE1(name, city) values ('Person B', 'BJ');
insert into TABLE1(name, city) values ('Person C', 'SH');
insert into TABLE1(name, city) values ('Person D', 'SZ');
commit;
drop table table2;
CREATE TABLE `andrew`.`table2`
(
`name` VARCHAR(32) NOT NULL,
`city` VARCHAR(32) NOT NULL
)
ENGINE = MyISAM;
insert into TABLE2(name, city) values ('Person W', 'BJ');
insert into TABLE2(name, city) values ('Person X', 'SH');
insert into TABLE2(name, city) values ('Person Y', 'SH');
insert into TABLE2(name, city) values ('Person Z', 'NJ');
commit;
1. 外连接
drop table table1;
CREATE TABLE `andrew`.`table1`
(
`name` VARCHAR(32) NOT NULL,
`city` VARCHAR(32) NOT NULL
)
ENGINE = MyISAM;
insert into TABLE1(name, city) values ('Person A', 'BJ');
insert into TABLE1(name, city) values ('Person B', 'BJ');
insert into TABLE1(name, city) values ('Person C', 'SH');
insert into TABLE1(name, city) values ('Person D', 'SZ');
commit;
drop table table2;
CREATE TABLE `andrew`.`table2`
(
`name` VARCHAR(32) NOT NULL,
`city` VARCHAR(32) NOT NULL
)
ENGINE = MyISAM;
insert into TABLE2(name, city) values ('Person W', 'BJ');
insert into TABLE2(name, city) values ('Person X', 'SH');
insert into TABLE2(name, city) values ('Person Y', 'SH');
insert into TABLE2(name, city) values ('Person Z', 'NJ');
commit;
1. 外连接