Breaking News

Script for database (Select two table)

Example of database table :
The table name is Names

CodeName
A01Leo
A02Aries
A03Taurus

Example of database table :
The table name is Values

CodeValue
A0190
A02100
A0395


  • 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:
CodeNamesValue
A01Leo90
A02Aries100
A03Taurus95

  • 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:
CodeNamesValue
A01Leo90
A02Aries100
A03Taurus95

  • Cartesian (Select all without where)
SELECT *
FROM Table_name, Table_name
Example:
SELECT *
FROM Names, Values
The display is:
CodeNamesValue
A01Leo90
A02Aries100
A03Taurus95

  • Equijoin
Equijoin is join table use where. the example is same with the alias example.

No comments