[Mysql 查询语句]——查询字段
查询所有字段
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 | +-------------+----------------+-----------------+