COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
tblCustomers (danh saùch khaùch haøng)
[CustID] int auto_increment Primary key,
[CustName] [varchar] (50) NULL ,
[Address] [varchar] (100) NULL,
[Tel] [varchar] (20) NULL,
[FaxNo] [varchar] (20) NULL,
[Email] [varchar] (50) NULL,
[Contact] [varchar] (50) NULL
[Country] [varchar] (3) NULL,
[Province] [varchar] (3) NULL
tblOrders (Hôïp ñoàng baùn haøng)
[OrderID] [int] Not null
auto_increment
Primary
Key,
[OrderDate] [date] NULL ,
[CustID]
int
,
[Description] [varchar] (200) NULL ,
[ShipCost] [float] NULL ,
[TranID] [tinyint] NULL ,
[PaymentID] [tinyint] NULL ,
[Amount] [float] NULL ,
[TotalAmount] [float] NULL ,
tblOrderDetails
(Hôïp
ñoàng baùn haøng chi tieát)
[SubID] [int] auto_increment NOT NULL ,
[OrderID] int ,
[ItemID]
int,
[No]
int,
[Qtty] [int] NULL ,
[Price] int NULL ,
[Discount] [Float] NULL ,
[Amount]
[Float]
NULL
tblItems (Danh saùch saûn phaåm)
[ItemID] int auto_increment Primary key,
[ItemName] [varchar] (200) NULL ,
[Unit] [nvarchar] (20) NULL ,
[Cost] [Float] NULL ,
[Active] [tinyint] NOT NULL ,
[Category]
int
Baïn coù theå tìm thaáy caùc baûng döõ lieäu coøn laïi trong döõ lieäu Test trong ñóa ñính keøm theo saùch.
6.3.
Meänh ñeà INNER JOIN
Phaùt bieåu SQL daïng SELECT coù söû duïng meänh ñeà INNER JOIN thöôøng duøng ñeå keát hôïp hai
hay nhieàu baûng döõ lieäu laïi vôùi nhau, cuù phaùp cuûa SELECT coù söû duïng meänh ñeà INNER JOIN:
SELECT [SELECT LIST]
FROM <FIRST_TABLENAME>
INNER JOIN <SECOND_TABLENAME>
ON <JOIN CONDITION>
WHERE <CRITERIANS>
ORDER BY <COLUMN LIST>
[ASC / DESC]
Neáu baïn caàn laáy ra moät soá coät trong caùc baûng coù keát noái laïi vôùi nhau baèng meänh ñeà INNER
JOIN thì cuù phaùp naøy vieát laïi nhö sau:
SELECT [FIELD1,FIELD2, ...]
FROM <FIRST_TABLENAME>
INNER JOIN <SECOND_TABLENAME>
Giaùo vieân: Phaïm Höõu Khang