getting joins

select * from a innner join b on a.id = b.id
内联合只生成同事匹配a和b的记录集,即a和b的子集

select * from a full outer join b on a.id = b.id
全外联合生成表a和b的记录全集,包括两边都匹配的记录,如果有一边没有匹配的,缺失的这一边为null,即a和b的并集

select * from a left outer join b on a.id = b.id
左外联合生成表a的所有记录,包括在表b里匹配的记录,如果没有匹配的,右边将是null

select * from a left join a on a.id = b.id where b.id is null
为了生成只在表a里而不再表b中的记录集,我们用同样的左外联合,然后用where 语句 排除 我们不想要的记录

select * from a full outer join b on a.id =b.id where a.id is null or b.id is null
为了生成对于表a和表b唯一的记录集,我们 用同样的全外联合,然后用where 语句排除两边都不想要的记录。

select * from a cross join b
其实就是a的每条数据和b的每条数据进行重新组合的最大集合。
即 a的数量*b的数量

你可能感兴趣的:(getting joins)