Rechercher dans le manuel MySQL
3.3.4.3 Selecting Particular Columns
If you do not want to see entire rows from your table, just
name the columns in which you are interested, separated by
commas. For example, if you want to know when your animals
were born, select the name
and
birth
columns:
- +----------+------------+
- | name | birth |
- +----------+------------+
- | Fluffy | 1993-02-04 |
- | Claws | 1994-03-17 |
- | Buffy | 1989-05-13 |
- | Fang | 1990-08-27 |
- | Bowser | 1989-08-31 |
- | Chirpy | 1998-09-11 |
- | Whistler | 1997-12-09 |
- | Slim | 1996-04-29 |
- | Puffball | 1999-03-30 |
- +----------+------------+
To find out who owns pets, use this query:
- +--------+
- | owner |
- +--------+
- | Harold |
- | Gwen |
- | Harold |
- | Benny |
- | Diane |
- | Gwen |
- | Gwen |
- | Benny |
- | Diane |
- +--------+
Notice that the query simply retrieves the
owner
column from each record, and some of
them appear more than once. To minimize the output, retrieve
each unique output record just once by adding the keyword
DISTINCT
:
- +--------+
- | owner |
- +--------+
- | Benny |
- | Diane |
- | Gwen |
- | Harold |
- +--------+
You can use a WHERE
clause to combine row
selection with column selection. For example, to get birth
dates for dogs and cats only, use this query:
- +--------+---------+------------+
- | name | species | birth |
- +--------+---------+------------+
- | Fluffy | cat | 1993-02-04 |
- | Claws | cat | 1994-03-17 |
- | Buffy | dog | 1989-05-13 |
- | Fang | dog | 1990-08-27 |
- | Bowser | dog | 1989-08-31 |
- +--------+---------+------------+
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-selecting-columns.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.