Rechercher dans le manuel MySQL
3.3.4.2 Selecting Particular Rows
As shown in the preceding section, it is easy to retrieve an
entire table. Just omit the WHERE
clause
from the SELECT
statement. But
typically you don't want to see the entire table, particularly
when it becomes large. Instead, you're usually more interested
in answering a particular question, in which case you specify
some constraints on the information you want. Let's look at
some selection queries in terms of questions about your pets
that they answer.
You can select only particular rows from your table. For example, if you want to verify the change that you made to Bowser's birth date, select Bowser's record like this:
- +--------+-------+---------+------+------------+------------+
- | name | owner | species | sex | birth | death |
- +--------+-------+---------+------+------------+------------+
- | Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
- +--------+-------+---------+------+------------+------------+
The output confirms that the year is correctly recorded as 1989, not 1979.
String comparisons normally are case-insensitive, so you can
specify the name as 'bowser'
,
'BOWSER'
, and so forth. The query result is
the same.
You can specify conditions on any column, not just
name
. For example, if you want to know
which animals were born during or after 1998, test the
birth
column:
- +----------+-------+---------+------+------------+-------+
- | name | owner | species | sex | birth | death |
- +----------+-------+---------+------+------------+-------+
- +----------+-------+---------+------+------------+-------+
You can combine conditions, for example, to locate female dogs:
- +-------+--------+---------+------+------------+-------+
- | name | owner | species | sex | birth | death |
- +-------+--------+---------+------+------------+-------+
- +-------+--------+---------+------+------------+-------+
The preceding query uses the AND
logical operator. There is also an
OR
operator:
- +----------+-------+---------+------+------------+-------+
- | name | owner | species | sex | birth | death |
- +----------+-------+---------+------+------------+-------+
- +----------+-------+---------+------+------------+-------+
AND
and
OR
may be intermixed, although
AND
has higher precedence than
OR
. If you use both operators, it
is a good idea to use parentheses to indicate explicitly how
conditions should be grouped:
- +-------+--------+---------+------+------------+-------+
- | name | owner | species | sex | birth | death |
- +-------+--------+---------+------+------------+-------+
- +-------+--------+---------+------+------------+-------+
Traduction non disponible
Le manuel MySQL n'est pas encore traduit en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Document créé le 26/06/2006, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/mysql-rf-selecting-rows.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.