一、建表
create table Guoji_A (
id bigint primary key AUTO_INCREMENT,
name varchar(20) ,
tel bigint
)
create table Guoji_B (
id bigint primary key AUTO_INCREMENT,
name varchar(20) ,
address bigint
)
二、插数据
insert into Guoji_A values (null,“大娃”,186),(null,“二娃”,187),(null,“三娃”,188),(null,“五娃”,189);
insert into Guoji_B values (null,“二娃”,10002),(null,“三娃”,10003),(null,“四娃”,10004);
三、表关联
select * from Guoji_A a left join Guoji_B b on a.name = b.name;
select * from Guoji_A a right join Guoji_B b on a.name = b.name;
☆☆☆☆☆☆mysql不支持全连接 用左连接联合右连接
select * from Guoji_A a LEFT JOIN Guoji_B b on a.name = b.name
UNION select * from Guoji_A a RIGH