标签:png out val ble ora mamicode into 苹果 bsp
创建两张表,代表两个店铺,每个店铺有不同的,每个柜台卖不同的商品。
1 /* 2 两个商店,每个店有不同的柜台,每个柜台上卖有不同的商品 3 */ 4 create table tableA( 5 id int(10) not null primary key auto_increment, 6 monorail varchar(20), 7 variety varchar(50) 8 ); 9 insert into tableA 10 values (1,‘a1‘,‘苹果‘),(2,‘a1‘,‘梨‘),(3,‘a3‘,‘香蕉‘),(4,‘a4‘,‘苹果‘),(5,‘a5‘,‘西瓜‘), 11 (6,‘a6‘,‘苹果‘),(7,‘a7‘,‘葡萄‘),(8,‘a8‘,‘桃子‘); 12 create table tableB( 13 id int(10) not null primary key auto_increment, 14 monorail varchar(20), 15 variety varchar(50) 16 ); 17 insert into tableB 18 values (1,‘b1‘,‘虾‘),(2,‘b2‘,‘猪肉‘),(3,‘b3‘,‘苹果‘),(4,‘b4‘,‘西瓜‘),(5,‘b5‘,‘梨‘), 19 (6,‘b6‘,‘香蕉‘);
两个表数据如下:
1.内连接
/* 内连接,查处两个商店共有的商品 */ select * from tablea A INNER JOIN tableb B on A.variety = B.variety ;
运行结果
2.左连接
/* 左连接,以A表为左表 */ select * from tablea A LEFT JOIN tableb B on A.variety = B.variety ;
运行结果
3.右连接
/* 右连接,以A表为左表 */ select * from tablea A RIGHT JOIN tableb B on A.variety = B.variety ;
运行结果
4.左外连接
/* 左外连接,以A表为左表 */ select * from tablea A LEFT JOIN tableb B on A.variety = B.variety Where B.variety is null;
运行结果
5.右外连接
/* 右外连接,以A表为左表 */ select * from tablea A RIGHT JOIN tableb B on A.variety = B.variety Where A.variety is null;
6.全连接 mysql不支持full (outer) join 故使用union代替
/* 全连接 */ select * from tablea A LEFT JOIN tableb B on A.variety = B.variety ; union select * from tablea A RIGHT JOIN tableb B on A.variety = B.variety ;
运行结果
7.全外连接
select * from tablea A LEFT JOIN tableb B on A.variety = B.variety Where B.variety is null union select * from tablea A RIGHT JOIN tableb B on A.variety = B.variety Where A.variety is null
运行结果
标签:png out val ble ora mamicode into 苹果 bsp
原文地址:https://www.cnblogs.com/xyzyj/p/10518193.html