[Mysql 查詢語句]——查詢欄位

Jelly_lyj發表於2017-03-18

查詢所有欄位

    select  *  from  表名;

    可以用 * 號代表所有欄位

select * from vendors;
+---------+----------------+-----------------+-------------+------------+----------+--------------+
| vend_id | vend_name      | vend_address    | vend_city   | vend_state | vend_zip | vend_country |
+---------+----------------+-----------------+-------------+------------+----------+--------------+
|    1001 | Anvils R Us    | 123 Main Street | Southfield  | MI         | 48075    | USA          |
|    1002 | LT Supplies    | 500 Park Street | Anytown     | OH         | 44333    | USA          |
|    1003 | ACME           | 555 High Street | Los Angeles | CA         | 90046    | USA          |
|    1004 | Furball Inc.   | 1000 5th Avenue | New York    | NY         | 11111    | USA          |
|    1005 | Jet Set        | 42 Galaxy Road  | London      | NULL       | N16 6PS  | England      |
|    1006 | Jouets Et Ours | 1 Rue Amusement | Paris       | NULL       | 45678    | France       |
+---------+----------------+-----------------+-------------+------------+----------+--------------+

 

查詢指定欄位

   select 欄位名1,欄位名2 from 表名;

   select 欄位名1 as 別名1, 欄位名2 as 別名2 from 表名;

   可以只指定查詢想查詢的欄位,改變順序和為這些欄位定義別名輸出都可以

select vend_id,vend_city,vend_name from vendors;
+---------+-------------+----------------+
| vend_id | vend_city   | vend_name      |
+---------+-------------+----------------+
|    1001 | Southfield  | Anvils R Us    |
|    1002 | Anytown     | LT Supplies    |
|    1003 | Los Angeles | ACME           |
|    1004 | New York    | Furball Inc.   |
|    1005 | London      | Jet Set        |
|    1006 | Paris       | Jouets Et Ours |
+---------+-------------+----------------+

select vend_id as 供貨商ID,vend_name as 供貨商名,vend_city as 供貨商城市 from vendors;
+-------------+----------------+-----------------+
| 供貨商ID    | 供貨商名       | 供貨商城市      |
+-------------+----------------+-----------------+
|        1001 | Anvils R Us    | Southfield      |
|        1002 | LT Supplies    | Anytown         |
|        1003 | ACME           | Los Angeles     |
|        1004 | Furball Inc.   | New York        |
|        1005 | Jet Set        | London          |
|        1006 | Jouets Et Ours | Paris           |
+-------------+----------------+-----------------+

 

相關文章