COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
2 1000
12000 14400000
3 5000
12000 72000000
3 6000 12000 86400000
4 8000 12000 15200000
4 8000 12000 15200000
4 8000 10000 15200000
5 9000 12000 29600000
5 9000
12000 129600000
5 9000 12000 129600000
5.6.
Phaùt bieåu SQL daïng SELECT vôùi DISTINCT
Neáu coù moät hay nhieàu baûng keát noái vôùi nhau, seõ xaûy ra truøng laëp nhieàu maåu tin. Nhöng trong
tröôøng hôïp naøy baïn chæ caàn laáy ra moät maåu tin trong taäp maåu tin truøng laëp, baïn söû duïng phaùt bieåu
SQL daïng SELECT vôùi chæ ñònh DISTINCT.
Ví duï 8-14: Phaùt bieåu SQL daïng SELECT
Select ItemID,Qtty,Price,Amount
from tblOrderDetails
order by Qtty
Keát quaû traû veà nhö sau:
ItemID
Qtty Price Amount
----------------------------------------------
1
900
12000 12960000
2 1000 12000 14400000
3 5000 12000 72000000
3 6000 12000 86400000
4 8000 12000 115200000
4 8000 12000 115200000
4 8000 10000 115200000
5 9000 12000 129600000
5 9000 12000 129600000
5 9000 12000 129600000
...
...
Ví duï 8-15: Phaùt bieåu SQL daïng SELECT vôùi DISTINCT
Select Distinct ItemID,Qtty,Price,Amount
From tblOrderDetails
Order by Qtty
Keát quaû loaïi boû nhöõng maåu tin truøng laép nhö sau:
ItemID
Qtty Price Amount
----------------------------------------------
1
900
12000 12960000
2 1000 12000 14400000
3 6000 12000 86400000
4 8000 12000 115200000
5 9000 12000 129600000
...
...
...
Giaùo vieân: Phaïm Höõu Khang