Join condition specified with ON can also contain conditions that do not relate directly to the join : Left Join « Table Joins « PostgreSQL

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
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
PostgreSQL » Table Joins » Left Join 
Join condition specified with ON can also contain conditions that do not relate directly to the 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=# -- The join condition specified with ON can also contain conditions that do not relate directly
postgres=# -- to the join. This can prove useful for some queries but needs to be thought out carefully.
postgres=#
postgres=# SELECT FROM t1 LEFT JOIN t2 ON t1.num = t2.num AND t2.name = 'xxx';
 num | name | num | name
-----+------+-----+------
   | a    |   | xxx
   | b    |     |
   | c    |     |
(rows)

postgres=#
postgres=# drop table t1;
DROP TABLE
postgres=# drop table t2;
DROP TABLE
postgres=#
postgres=#
           
       
Related examples in the same category
1. LEFT JOIN sample
2. LEFT JOIN two tables USING a column name
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.