COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
13
ASW-60VT
NULL
14
ASW-660T 120V TW 29340 NULL
14
ASW-685V 120V TW 29440 NULL
15
ASW60VP 220V 34571 NULL
16
ASW-45Z1T1
2960000
17
ASW-45Y1T
127V
14400000
18
ASW-45Y1T 220V
72000000
19
ASW-45Y1T 220V
86400000
20
ASW-45Z1T
15200000
...
6.5.
Meänh ñeà Right Join
Ngöôïc laïi vôùi phaùt bieåu SQL daïng SELECT söû duïng meänh ñeà LEFT JOIN laø phaùt bieåu SQL
daïng SELECT söû duïng meänh ñeà RIGHT JOIN seõ xuaát döõ lieäu cuûa baûng beân phaûi cho duø döõ lieäu cuûa
baûng beân traùi khoâng toàn taïi, cuù phaùp coù daïng:
Select <Column list>
From lefttablename
RIGHT JOIN righttablename
On lefttabkename.field1=righttablename.field2
Where <conditions>
Order by <column name>
ASC/DESC
Trong ví duï sau, baïn coù theå choïn ra taát caû caùc saûn phaåm coù hay khoâng coù doanh soá baùn trong
thaùng hieän taïi. Caùc saûn phaåm khoâng toàn taïi doanh soá baùn seõ khoâng hieän ra.
Ví duï 8-27: SELECT duøng RIGHT JOIN
/* in ra danh saùch saûn phaåm baùn trong thaùng ngaøy 17 */
/* trong phaùt bieåu SELECT naøy coù söû duïng meänh ñeà
WHERE söû duïng phaùt bieåu SELECT khaùc, keát quaû cuûa SELECT trong meänh ñeà WHERE traû veà moät maûng
OrderID */
Select ItemName,Qtty,
Price,Amount
From tblItems
Right join tblOrderDetails
On tblItems.ItemID=tblOrderDetails.ItemID
Where OrderID in (12,14,23,15)
Order by ItemID
Keát quaû traû veà nhö sau:
ItemName
Qtty Price Amount
----------------------------------------------
ASW-45Y1T 127V SDIA29350 11000 12000 58400000
ASW-45Y1T 127V SDIA29350 10000 12000 44000000
ASW-45Y1T 127V SDIA 29350 10000 12000 14400000
ASW-45Y1T 127V SDIA 29350 10000 12000 44000000
ASW-45Y1T 127V SDIA 29350 11000 12000 58400000
ASW-45Y1T 127V SDIA 29350 10000 12000 44000000
ASW-45Y1T 127V SDIA 29350 11000 12000 58400000
ASW-45Y1T 220V ARG 29391 6000 12000 86400000
ASW-45Z1T
9000 12000 29600000
ASW-45Z1T
9000 12000 29600000
...
Giaùo vieân: Phaïm Höõu Khang