Script for database (Select two table)
Example of
database table :
The table name is Names
Example of database table :
The table name is Values
The table name is Names
Code | Name |
A01 | Leo |
A02 | Aries |
A03 | Taurus |
Example of database table :
The table name is Values
Code | Value |
A01 | 90 |
A02 | 100 |
A03 | 95 |
- Query with two table
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:
Code | Names | Value |
A01 | Leo | 90 |
A02 | Aries | 100 |
A03 | Taurus | 95 |
- Using alias
SELECT
Alias1.Field_name, Alias2.Field_name,....
FROM
Table_name Alias1, Table_name Alias2
WHERE Condition
Example:
SELECT A.Code, A.Name,
B.Value
FROM Names A, Values B
WHERE A.Code=B.Code
The
display is:
Code | Names | Value |
A01 | Leo | 90 |
A02 | Aries | 100 |
A03 | Taurus | 95 |
- Cartesian (Select all without where)
SELECT
*
FROM Table_name, Table_name
Example:
SELECT *
FROM
Names, Values
The display is:
Code | Names | Value |
A01 | Leo | 90 |
A02 | Aries | 100 |
A03 | Taurus | 95 |
- Equijoin
Equijoin is join table use where. the example is same with
the alias example.
No comments