Script for database (Select two table use Inner Join, Right Join, Left Join, and Full Join)
Example of
database table :
The table name is Names
Example of database table :
The table name is Values
SELECT Table_name.Field_name, Table_name.Field_name, .......
FROM Table_name, Table_name
WHERE Condition
Example:
SELECT Names.Code, Names.Name, Values.Value
FROM Names, Values
WHERE Names.Code = Values.Code
The display is
SELECT Table_name.Field_name, Table_name.Field_name, .......
FROM Table_name
RIGHT JOIN Table_name
WHERE Condition
Example:
SELECT Names.Code, Names.Name, Values.Value
FROM Names
RIGHT JOIN Values
WHERE Names.Code = Values.Code
The display is
SELECT Table_name.Field_name, Table_name.Field_name, .......
FROM Table_name
LEFT JOIN Table_name
WHERE Condition
Example:
SELECT Names.Code, Names.Name, Values.Value
FROM Names
LEFT JOIN Values
WHERE Names.Code = Values.Code
The display is
SELECT Table_name.Field_name, Table_name.Field_name, .......
FROM Table_name
FULL JOIN Table_name
WHERE Condition
Example:
SELECT Names.Code, Names.Name, Values.Value
FROM Names
FULL JOIN Values
WHERE Names.Code = Values.Code
The display is
The table name is Names
Code | Name |
A01 | Leo |
A02 | Aries |
A03 | Taurus |
A04 | Gemini |
Example of database table :
The table name is Values
Code | Value |
A01 | 90 |
A02 | 100 |
A03 | 95 |
Inner join
Inner join for display record where both correctSELECT Table_name.Field_name, Table_name.Field_name, .......
FROM Table_name, Table_name
WHERE Condition
Example:
SELECT Names.Code, Names.Name, Values.Value
FROM Names, Values
WHERE Names.Code = Values.Code
The display is
Code | Names | Value |
A01 | Leo | 90 |
A02 | Aries | 100 |
A03 | Taurus | 95 |
Right join
Right join for display record by the right tableSELECT Table_name.Field_name, Table_name.Field_name, .......
FROM Table_name
RIGHT JOIN Table_name
WHERE Condition
Example:
SELECT Names.Code, Names.Name, Values.Value
FROM Names
RIGHT JOIN Values
WHERE Names.Code = Values.Code
The display is
Code | Names | Value |
A01 | Leo | 90 |
A02 | Aries | 100 |
A03 | Taurus | 95 |
Left join
Left join for display records by the left tableSELECT Table_name.Field_name, Table_name.Field_name, .......
FROM Table_name
LEFT JOIN Table_name
WHERE Condition
Example:
SELECT Names.Code, Names.Name, Values.Value
FROM Names
LEFT JOIN Values
WHERE Names.Code = Values.Code
The display is
Code | Names | Value |
A01 | Leo | 90 |
A02 | Aries | 100 |
A03 | Taurus | 95 |
A04 | Gemini |
Full join
Full join for display all records in tablesSELECT Table_name.Field_name, Table_name.Field_name, .......
FROM Table_name
FULL JOIN Table_name
WHERE Condition
Example:
SELECT Names.Code, Names.Name, Values.Value
FROM Names
FULL JOIN Values
WHERE Names.Code = Values.Code
The display is
Code | Names | Value |
A01 | Leo | 90 |
A02 | Aries | 100 |
A03 | Taurus | 95 |
A04 | Gemini |
No comments