PostgreSQL/Table Joins/Right Join

Материал из SQL эксперт
Перейти к: навигация, поиск

RIGHT JOIN two tables ON

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 RIGHT JOIN t2 ON t1.num = t2.num;
 num | name | num | name
-----+------+-----+------
   1 | a    |   1 | xxx
   3 | c    |   3 | yyy
     |      |   5 | zzz
(3 rows)
postgres=#
postgres=# drop table t1;
DROP TABLE
postgres=# drop table t2;
DROP TABLE
postgres=#
postgres=#