SQL SELECT
SELECT“欄位名稱” FROM“表格名稱”; 我們用以下的例子來實作: 北風資料庫 (Northwind)
Customers 的資料表
SELECT * FROM Customers ;
CustomerID |
CompanyName |
ContactName |
Address |
City |
PostalCode |
Country |
ALFKI |
Alfreds Futterkiste |
Maria Anders |
Obere Str. 57 |
Berlin |
12209 |
Germany |
ANATR |
Ana Trujillo Emparedados y helados |
Ana Trujillo |
Avda. de la Constitucion 2222 |
Mexico D.F. |
05021 |
Mexico |
ANTON |
Antonio Moreno Taqueria |
Antonio Moreno |
Mataderos 2312 |
Mexico D.F. |
05023 |
Mexico |
AROUT |
Around the Horn |
Thomas Hardy |
120 Hanover Sq. |
London |
WA1 1DP |
UK |
BERGS |
Berglunds snabbkop |
Christina Berglund |
Berguvsvagen 8 |
Lulea |
S-958 22 |
Sweden |
BLAUS |
Blauer See Delikatessen |
Hanna Moos |
Forsterstr. 57 |
Mannheim |
68306 |
Germany |
BLONP |
Blondesddsl pere et fils |
Frederique Citeaux |
24, place Kleber |
Strasbourg |
67000 |
France |
BOLID |
Bolido Comidas preparadas |
Martin Sommer |
C/ Araquil, 67 |
Madrid |
28023 |
Spain |
BONAP |
Bon app' |
Laurence Lebihan |
12, rue des Bouchers |
Marseille |
13008 |
France |
BOTTM |
Bottom-Dollar Markets |
Elizabeth Lincoln |
23 Tsawassen Blvd. |
Tsawassen |
T2F 8M4 |
Canada |
備註:星號(*)為查詢所有列的參數
從資料表中選出所有公司名稱 CompanyName
SELECT CompanyName FROM Customers ;
結果:
CompanyName |
Alfreds Futterkiste |
Ana Trujillo Emparedados y helados |
Antonio Moreno Taqueria |
Around the Horn |
Berglunds snabbkop |
Blauer See Delikatessen |
Blondesddsl pere et fils |
Bolido Comidas preparadas |
Bon app' |
Bottom-Dollar Markets |