COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
tablename*/
Ví duï 8-3: phaùt bieåu phaùt bieåu SQL daïng Select
Select *
From tblCountries
/* Lieät keâ taát caû caùc quoác gia trong baûng tblCountries hoaëc baïn coù theå lieät keâ teân nhö phaùt bieåu sau */
Select CountryName
From
tblCountries
Keát quaû traû veà nhö sau:
CountryCode CountryName
-------- ---------- ------------ -------------
VNA
Vietnam
SNG
Singapore
USS
United
Stated
UKD
United
Kingdom
GER
Germany
CAM
Cambodia
THA
Thai
Land
MAL
Malaysia
INC
Indonesia
CHN
China
5.2.3. Phaùt bieåu SQL daïng SELECT vôùi meänh ñeà Where
Khi baïn duøng meänh ñeà WHERE ñeå taïo neân tieâu chuaån caàn loïc maåu tin theo tieâu chuaån ñöôïc
ñònh nghóa, thoâng thöôøng WHERE duøng coät (tröôøng) ñeå so saùnh vôùi giaù trò, coät khaùc, hay bieåu thöùc
chöùa coät (tröôøng) baát kyø coù trong baûng. Phaùt bieåu SQL daïng Select vôùi meänh ñeà Where cuù phaùp coù
daïng nhö sau:
Select *
from tablename
where conditions
Select field1, field2, field3
from tablename
where conditions
Vôùi conditions trong caû hai phaùt bieåu treân ñöôïc ñònh nghóa ñieàu kieän truy vaán nhö khai baùo sau:
Select *
From tablename
where field1>10
select *
from tblCountries
where CountryCode in('VNA','CHN')
Caùc pheùp toaùn so saùnh trong conditions bao goàm:
♦
> : lôùn hôn where Amount > 100000;
♦
< : nhoû hôn where Amount < 100000;
♦
>= : lôùn hôn hoaëc baèng where Amount >= 100000;
♦
>= : nhoû hôn hoaëc baèng where Amount <= 100000;
♦
= :
baèng where
CustID=’12';
Giaùo vieân: Phaïm Höõu Khang