Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Difference between full,inner,left,right
Message
 
To
13/04/2006 13:16:29
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01113517
Message ID:
01113525
Views:
14
>what is the difference between full join , inner join ,left outer join , right outer join ?
Easier for me to explain with examples:
Two Tables
Table1
ID   Field1
------------
1    FldId1
2    FldId2
3    FldId3

Table2
Tbl2ID   Tbl2Field1
-------------------
1        Tbl2FldId1
3        Tbl2FldId3
4        Tbl2FldId4


*** FULL JOIN:
*** All records from first table are combined with all records from second table
SELECT Table1.*, Table2.* FROM Table1;
       FULL JOIN Table2

** Result:
Id Field1  Tbl2Id  Tbl2Field1
------------------------------
1  FldId1    1     Tbl2FldId1
1  FldId1    3     Tbl2FldId3
1  FldId1    4     Tbl2FldId4
2  FldId2    1     Tbl2FldId1
2  FldId2    3     Tbl2FldId3
2  FldId2    4     Tbl2FldId4
3  FldId3    1     Tbl2FldId1
3  FldId3    3     Tbl2FldId3
3  FldId3    4     Tbl2FldId4

*** INNER JOIN
*** Only condition matching records are in result set
SELECT Table1.*, Table2.* FROM Table1;
       INNER JOIN Table2 ON Table1.Id = Table2.Tbl2Id

** Result:

Id Field1  Tbl2Id  Tbl2Field1
------------------------------
1  FldId1    1     Tbl2FldId1
3  FldId3    3     Tbl2FldId3



*** LEFT JOIN:
*** All records from Table from the left and matching records fropm the table from the rigth
SELECT Table1.*, Table2.* FROM Table1;
       LEFT JOIN Table2 ON Table1.Id = Table2.Tbl2Id

** Result:

Id Field1  Tbl2Id  Tbl2Field1
------------------------------
1  FldId1    1     Tbl2FldId1
2  FldId2   NULL   NULL
3  FldId3    3     Tbl2FldId3



*** RIGHT JOIN:
*** All records from Table from the right and matching records fropm the table from the left
SELECT Table1.*, Table2.* FROM Table1;
       RIGHT JOIN Table2 ON Table1.Id = Table2.Tbl2Id

** Result:

Id Field1  Tbl2Id  Tbl2Field1
------------------------------
1    FldId1    1     Tbl2FldId1
3    FldId3    3     Tbl2FldId3
NULL NULL      4     Tbl2FldId4
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform