如果您不希望从表中看到整行,只需命名您感兴趣的列,用逗号分隔。例如,如果您想知道您的动物何时出生,请选择name和birth列:

    1. mysql> SELECT name, birth FROM pet;
    2. +----------+------------+
    3. | name | birth |
    4. +----------+------------+
    5. | Fluffy | 1993-02-04 |
    6. | Claws | 1994-03-17 |
    7. | Buffy | 1989-05-13 |
    8. | Fang | 1990-08-27 |
    9. | Bowser | 1989-08-31 |
    10. | Chirpy | 1998-09-11 |
    11. | Whistler | 1997-12-09 |
    12. | Slim | 1996-04-29 |
    13. | Puffball | 1999-03-30 |
    14. +----------+------------+

    要了解都谁拥有宠物,请使用此查询:

    mysql> SELECT owner FROM pet;
    +--------+
    | owner  |
    +--------+
    | Harold |
    | Gwen   |
    | Harold |
    | Benny  |
    | Diane  |
    | Gwen   |
    | Gwen   |
    | Benny  |
    | Diane  |
    +--------+
    

    请注意,查询仅从每条记录中检索所有者列,其中一些记录出现不止一次。为了最小化输出,只需添加一个关键字DISTINCT,每次检索出不重复的记录集:

    mysql> SELECT DISTINCT owner FROM pet;
    +--------+
    | owner  |
    +--------+
    | Benny  |
    | Diane  |
    | Gwen   |
    | Harold |
    +--------+