## Sample to explain Join syntax
### Data Preparation
```SQL
-- create table
.header on
.mode column
.timer on
create table person (id Integer, name text);
create table account (id Integer, status text);
insert into person values (1, 'a');
insert into person values (2, 'b');
insert into person values (3, 'c');
insert into account values (1, 't');
insert into account values (2, 't');
insert into account values (4, 't');
```
out put of those two table
```bash
sqlite> select * from account;
id status
---------- ----------
1 t
2 t
4 f
sqlite> select * from person ;
id name
---------- ----------
1 a
2 b
3 c
```
### A Inner Join B
Inner join = default = no condition = 交集
```
sqlite> select a.id, a.status, p.id, p.name from account a, person p where a.id=p.id;
id status id name
---------- ---------- ---------- ----------
1 t 1 a
2 t 2 b
sqlite> select a.id, a.status, p.id, p.name from account a inner join person p on a.id=p.id;
id status id name
---------- ---------- ---------- ----------
1 t 1 a
2 t 2 b
sqlite> select a.id, a.status, p.id, p.name from account a join person p on a.id=p.id;
id status id name
---------- ---------- ---------- ----------
1 t 1 a
2 t 2 b
```
### A Left Join B
Left Join = 以左边为准, 没有的补 null
```sql
sqlite> select a.id, a.status, p.id, p.name from account a left join person p on a.id=p.id;
id status id name
---------- ---------- ---------- ----------
1 t 1 a
2 t 2 b
4 f
```
### A Right Join B
Right Join = 以右边为准, 没有的补 null -- sqlite not support right join and full join
workaround: A Right Join B = B Left Join A
```sql
sqlite> select a.id, a.status, p.id, p.name from person p left join account a on a.id=p.id;
id status id name
---------- ---------- ---------- ----------
1 t 1 a
2 t 2 b
3 c
```
### A Full Join B
都选出来, 没有的各自补null
workaround: Full Outer Join = A Left Join B + A Right Join B = A Left Join B + B Left Join A, 最后结果集去重
```sql
```
### Outer 是一个副词, 没什么意义
帖子里有一个很有意思的 sub query, 加上了where = null, 之后, 选出了某一边 + 去重 结果
[LEFT JOIN vs. LEFT OUTER JOIN](https://stackoverflow.com/questions/406294/left-join-vs-left-outer-join-in-sql-server)
### Source
[ZEBTUT Guide](http://www.zentut.com/sql-tutorial/sql-outer-join/)