PostgreSQL full JOIN Multi-table joint query

Source: Internet
Author: User
Tags postgresql

As long as one of the tables has a match, the full JOIN keyword returns rows.

Full JOIN keyword syntax
SELECT column_name (s)
From table_name1
Full JOIN table_name2
On Table_name1.column_name=table_name2.column_name
Note: In some database tutorials, the full join is called the 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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.