LEFT JOIN sample : Left Join « Table Joins « PostgreSQL

Home
PostgreSQL
1.Aggregate Functions
2.Analytical Functions
3.Array
4.Constraints
5.Cursor
6.Data Type
7.Database
8.Date Timezone
9.Index
10.Inheritance
11.Insert Delete Update
12.Math Functions
13.Postgre SQL
14.Select Query
15.Sequence
16.Store Procedure Function
17.String Functions
18.Subquery
19.Table
20.Table Joins
21.Transaction
22.User Previliege
23.View
PostgreSQL » Table Joins » Left Join 
LEFT JOIN sample


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 LEFT JOIN t2 ON t1.num = t2.num;
 num | name | num | name
-----+------+-----+------
   | a    |   | xxx
   | b    |     |
   | c    |   | yyy
(rows)

postgres=#
postgres=# drop table t1;
DROP TABLE
postgres=# drop table t2;
DROP TABLE
postgres=#
           
       
Related examples in the same category
1.LEFT JOIN two tables USING a column name
2.Join condition specified with ON can also contain conditions that do not relate directly to the join
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.