mysql中join各種形式大全及操作和圖片
阿新 • • 發佈:2019-01-13
一:建立2張表
*join 建表語句*/ drop database if exists test; create database test; use test; /* 左表t1*/ drop table if exists t1; create table t1 (id int not null,name varchar(20)); insert into t1 values (1,'t1a'); insert into t1 values (2,'t1b'); insert into t1 values (3,'t1c'); insert into t1 values (4,'t1d'); insert into t1 values (5,'t1f'); /* 右表 t2*/ drop table if exists t1; create table t2 (id int not null,name varchar(20)); insert into t2 values (2,'t2b'); insert into t2 values (3,'t2c'); insert into t2 values (4,'t2d'); insert into t2 values (5,'t2f'); insert into t2 values (6,'t2a');
1.笛卡爾積
mysql> select * from t1 join t2;
2.左連線
兩表關聯,左表全部保留,右表關聯不上用null表示。
3.右連線
4、內連線
5、左表獨有
6、右表獨有
7、全連線
oracle裡面有full join,但是在mysql中沒有full join。我們可以使用union來達到目的。
8、並集去交集