PostgreSQL FULL JOIN 多表联合查询

WBOY
发布: 2016-06-07 17:48:17
原创
3158 人浏览过

只要其中某个表存在匹配,FULL JOIN 关键字就会返回行。

FULL JOIN 关键字语法
SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
注释:在某些中, FULL JOIN 称为 FULL OUTER JOIN。

 

postgres=#
postgres=# CREATE TABLE t1 (
postgres(#     num         int,
postgres(#     name       varchar(10)
postgres(# );
CREATE TABLE
postgres=#
postgres=# insert into t1 values(1,'a');
INSERT 0 1
postgres=# insert into t1 values(2,'b');
INSERT 0 1
postgres=# insert into t1 values(3,'c');
INSERT 0 1
postgres=#
postgres=# CREATE TABLE t2 (
postgres(#     num         int,
postgres(#     name       varchar(10)
postgres(# );
CREATE TABLE
postgres=#
postgres=# insert into t2 values(1,'xxx');
INSERT 0 1
postgres=# insert into t2 values(3,'yyy');
INSERT 0 1
postgres=# insert into t2 values(5,'zzz');
INSERT 0 1
postgres=#
postgres=# SELECT * FROM t1 FULL JOIN t2 ON t1.num = t2.num;
 num | name | num | name
-----+------+-----+------
   1 | a    |   1 | xxx
   2 | b    |     |
   3 | c    |   3 | yyy
     |      |   5 | zzz
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!