SlideShare a Scribd company logo
1 of 1
Download to read offline
http://www.tutorialspoint.com/sqlite/sqlite_left_outer_joins.htm Copyright © tutorialspoint.com
SQLITE - LEFT OUTER JOIN
An outer join does not require each record in the two joined tables to have a matching record.
There are three types of outer joins. Left outer joins, right outer joins, and full outer joins. SQLite
only supports left outer joins
The LEFT OUTER JOIN returns all values from the left table, even if there is no match with the
right table. It such rows, there will be NULL values. In other words, left outer join returns all the
values from the left table, plus matched values from the right table. Note, that the OUTER
keyword can be omitted.
Consider following two tables, (a) COMPANY table is as follows:
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Paul | 32 | California| 20000.00|
| 2 | Allen | 25 | Texas | 15000.00|
| 3 | Teddy | 23 | Norway | 20000.00|
| 4 | Mark | 25 | Rich-Mond | 65000.00|
| 5 | David | 27 | Texas | 85000.00|
| 6 | Kim | 22 | South-Hall| 45000.00|
| 7 | James | 24 | Houston | 10000.00|
+----+----------+-----+-----------+----------+
(b) Another table is ORDERS as follows:
+-----+---------------------+-------------+--------+
|OID | DATE | CUSTOMER_ID | AMOUNT |
+-----+---------------------+-------------+--------+
| 102 | 2009-10-08 00:00:00 | 3 | 3000 |
| 100 | 2009-10-08 00:00:00 | 3 | 1500 |
| 101 | 2009-11-20 00:00:00 | 2 | 1560 |
| 103 | 2008-05-20 00:00:00 | 4 | 2060 |
+-----+---------------------+-------------+--------+
Now let us join these two tables in our SELECT statement as follows:
SQL> sqlite> SELECT NAME, AMOUNT ,DATE FROM COMPANY LEFT JOIN ORDER
> ON COMPANY.Id = ORDER.CustomerId;
This would produce following result:
+----+----------+--------+---------------------+
| ID | NAME | AMOUNT | DATE |
+----+----------+--------+---------------------+
| 1 | Paul | 3000 | 2009-10-08 00:00:00 |
| 2 | Allen | 2060 | 2008-05-20 00:00:00 |
| 3 | Teddy | 2060 | 2008-05-20 00:00:00 |
| 4 | Mark | 2060 | 2008-05-20 00:00:00 |
| 5 | David | 2060 | 2008-05-20 00:00:00 |
| 6 | Kim | 2060 | 2008-05-20 00:00:00 |
| 7 | James | 2060 | 2008-05-20 00:00:00 |
+----+----------+--------+---------------------+

More Related Content

What's hot

2 Combinational Logic Circuit 01
2 Combinational Logic Circuit 012 Combinational Logic Circuit 01
2 Combinational Logic Circuit 01guestde204e
 
Half adder & full adder
Half adder & full adderHalf adder & full adder
Half adder & full adderGaditek
 
adder and subtractor
 adder and subtractor adder and subtractor
adder and subtractorUnsa Shakir
 
Booth's algorithm part 1
Booth's algorithm part 1Booth's algorithm part 1
Booth's algorithm part 1babuece
 
Top schools in faridabad
Top schools in faridabadTop schools in faridabad
Top schools in faridabadEdhole.com
 
Subtracter
SubtracterSubtracter
SubtracterKumar
 
Unsigned and Signed fixed point Addition and subtraction
Unsigned and Signed  fixed point Addition and subtractionUnsigned and Signed  fixed point Addition and subtraction
Unsigned and Signed fixed point Addition and subtractionciyamala kushbu
 

What's hot (10)

2 Combinational Logic Circuit 01
2 Combinational Logic Circuit 012 Combinational Logic Circuit 01
2 Combinational Logic Circuit 01
 
Half adder & full adder
Half adder & full adderHalf adder & full adder
Half adder & full adder
 
BCD ADDER
BCD ADDER BCD ADDER
BCD ADDER
 
adder and subtractor
 adder and subtractor adder and subtractor
adder and subtractor
 
Booth's algorithm part 1
Booth's algorithm part 1Booth's algorithm part 1
Booth's algorithm part 1
 
Top schools in faridabad
Top schools in faridabadTop schools in faridabad
Top schools in faridabad
 
Subtracter
SubtracterSubtracter
Subtracter
 
Subtractor
SubtractorSubtractor
Subtractor
 
Unsigned and Signed fixed point Addition and subtraction
Unsigned and Signed  fixed point Addition and subtractionUnsigned and Signed  fixed point Addition and subtraction
Unsigned and Signed fixed point Addition and subtraction
 
Đề Thi HK2 Toán 8 - THCS Đình Chiểu
Đề Thi HK2 Toán 8 - THCS Đình ChiểuĐề Thi HK2 Toán 8 - THCS Đình Chiểu
Đề Thi HK2 Toán 8 - THCS Đình Chiểu
 

Similar to Sqlite left outer_joins

Sq lite functions
Sq lite functionsSq lite functions
Sq lite functionspunu_82
 
kscope2013vst-130627142814-phpapp02.pdf
kscope2013vst-130627142814-phpapp02.pdfkscope2013vst-130627142814-phpapp02.pdf
kscope2013vst-130627142814-phpapp02.pdfTricantinoLopezPerez
 
SQL Tuning Methodology, Kscope 2013
SQL Tuning Methodology, Kscope 2013 SQL Tuning Methodology, Kscope 2013
SQL Tuning Methodology, Kscope 2013 Kyle Hailey
 
M|18 Understanding the Query Optimizer
M|18 Understanding the Query OptimizerM|18 Understanding the Query Optimizer
M|18 Understanding the Query OptimizerMariaDB plc
 
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
 Design and Develop SQL DDL statements which demonstrate the use of SQL objec... Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...bhavesh lande
 
MySQL Idiosyncrasies That Bite SF
MySQL Idiosyncrasies That Bite SFMySQL Idiosyncrasies That Bite SF
MySQL Idiosyncrasies That Bite SFRonald Bradford
 
data constraints,group by
data constraints,group by data constraints,group by
data constraints,group by Visakh V
 
OOUG: VST , visual sql tuning diagrams
OOUG: VST , visual sql tuning diagramsOOUG: VST , visual sql tuning diagrams
OOUG: VST , visual sql tuning diagramsKyle Hailey
 
MySQL Idiosyncrasies That Bite 2010.07
MySQL Idiosyncrasies That Bite 2010.07MySQL Idiosyncrasies That Bite 2010.07
MySQL Idiosyncrasies That Bite 2010.07Ronald Bradford
 

Similar to Sqlite left outer_joins (15)

Inner Join In Ms Access
Inner Join In Ms AccessInner Join In Ms Access
Inner Join In Ms Access
 
My sq ltutorial
My sq ltutorialMy sq ltutorial
My sq ltutorial
 
Sq lite functions
Sq lite functionsSq lite functions
Sq lite functions
 
kscope2013vst-130627142814-phpapp02.pdf
kscope2013vst-130627142814-phpapp02.pdfkscope2013vst-130627142814-phpapp02.pdf
kscope2013vst-130627142814-phpapp02.pdf
 
SQL Tuning Methodology, Kscope 2013
SQL Tuning Methodology, Kscope 2013 SQL Tuning Methodology, Kscope 2013
SQL Tuning Methodology, Kscope 2013
 
M|18 Understanding the Query Optimizer
M|18 Understanding the Query OptimizerM|18 Understanding the Query Optimizer
M|18 Understanding the Query Optimizer
 
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
 Design and Develop SQL DDL statements which demonstrate the use of SQL objec... Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
Design and Develop SQL DDL statements which demonstrate the use of SQL objec...
 
SQL Notes
SQL NotesSQL Notes
SQL Notes
 
MySQL Idiosyncrasies That Bite SF
MySQL Idiosyncrasies That Bite SFMySQL Idiosyncrasies That Bite SF
MySQL Idiosyncrasies That Bite SF
 
MySQL Functions
MySQL FunctionsMySQL Functions
MySQL Functions
 
Mysql and html
Mysql and html Mysql and html
Mysql and html
 
data constraints,group by
data constraints,group by data constraints,group by
data constraints,group by
 
OOUG: VST , visual sql tuning diagrams
OOUG: VST , visual sql tuning diagramsOOUG: VST , visual sql tuning diagrams
OOUG: VST , visual sql tuning diagrams
 
SAV
SAVSAV
SAV
 
MySQL Idiosyncrasies That Bite 2010.07
MySQL Idiosyncrasies That Bite 2010.07MySQL Idiosyncrasies That Bite 2010.07
MySQL Idiosyncrasies That Bite 2010.07
 

More from Nargis Ehsan

More from Nargis Ehsan (11)

Huffman codes
Huffman codesHuffman codes
Huffman codes
 
Sql5
Sql5Sql5
Sql5
 
Sql2
Sql2Sql2
Sql2
 
Sql statments c ha p# 1
Sql statments c ha p# 1Sql statments c ha p# 1
Sql statments c ha p# 1
 
Sql 3
Sql 3Sql 3
Sql 3
 
Quick sort algo analysis
Quick sort algo analysisQuick sort algo analysis
Quick sort algo analysis
 
Inner join and outer join
Inner join and outer joinInner join and outer join
Inner join and outer join
 
Erd chapter 3
Erd chapter 3Erd chapter 3
Erd chapter 3
 
The relational database model chapter 2
The relational database model  chapter 2The relational database model  chapter 2
The relational database model chapter 2
 
Communication network
Communication networkCommunication network
Communication network
 
Communication network .ppt
Communication network  .pptCommunication network  .ppt
Communication network .ppt
 

Sqlite left outer_joins

  • 1. http://www.tutorialspoint.com/sqlite/sqlite_left_outer_joins.htm Copyright © tutorialspoint.com SQLITE - LEFT OUTER JOIN An outer join does not require each record in the two joined tables to have a matching record. There are three types of outer joins. Left outer joins, right outer joins, and full outer joins. SQLite only supports left outer joins The LEFT OUTER JOIN returns all values from the left table, even if there is no match with the right table. It such rows, there will be NULL values. In other words, left outer join returns all the values from the left table, plus matched values from the right table. Note, that the OUTER keyword can be omitted. Consider following two tables, (a) COMPANY table is as follows: +----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Paul | 32 | California| 20000.00| | 2 | Allen | 25 | Texas | 15000.00| | 3 | Teddy | 23 | Norway | 20000.00| | 4 | Mark | 25 | Rich-Mond | 65000.00| | 5 | David | 27 | Texas | 85000.00| | 6 | Kim | 22 | South-Hall| 45000.00| | 7 | James | 24 | Houston | 10000.00| +----+----------+-----+-----------+----------+ (b) Another table is ORDERS as follows: +-----+---------------------+-------------+--------+ |OID | DATE | CUSTOMER_ID | AMOUNT | +-----+---------------------+-------------+--------+ | 102 | 2009-10-08 00:00:00 | 3 | 3000 | | 100 | 2009-10-08 00:00:00 | 3 | 1500 | | 101 | 2009-11-20 00:00:00 | 2 | 1560 | | 103 | 2008-05-20 00:00:00 | 4 | 2060 | +-----+---------------------+-------------+--------+ Now let us join these two tables in our SELECT statement as follows: SQL> sqlite> SELECT NAME, AMOUNT ,DATE FROM COMPANY LEFT JOIN ORDER > ON COMPANY.Id = ORDER.CustomerId; This would produce following result: +----+----------+--------+---------------------+ | ID | NAME | AMOUNT | DATE | +----+----------+--------+---------------------+ | 1 | Paul | 3000 | 2009-10-08 00:00:00 | | 2 | Allen | 2060 | 2008-05-20 00:00:00 | | 3 | Teddy | 2060 | 2008-05-20 00:00:00 | | 4 | Mark | 2060 | 2008-05-20 00:00:00 | | 5 | David | 2060 | 2008-05-20 00:00:00 | | 6 | Kim | 2060 | 2008-05-20 00:00:00 | | 7 | James | 2060 | 2008-05-20 00:00:00 | +----+----------+--------+---------------------+