Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code DEF204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

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:

  1. mysql> SELECT * FROM pet WHERE name = 'Bowser';
  2. +--------+-------+---------+------+------------+------------+
  3. | name   | owner | species | sex  | birth      | death      |
  4. +--------+-------+---------+------+------------+------------+
  5. | Bowser | Diane | dog     | m    | 1989-08-31 | 1995-07-29 |
  6. +--------+-------+---------+------+------------+------------+

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:

  1. mysql> SELECT * FROM pet WHERE birth >= '1998-1-1';
  2. +----------+-------+---------+------+------------+-------+
  3. | name     | owner | species | sex  | birth      | death |
  4. +----------+-------+---------+------+------------+-------+
  5. | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  6. | Puffball | Diane | hamster | f    | 1999-03-30 | NULL  |
  7. +----------+-------+---------+------+------------+-------+

You can combine conditions, for example, to locate female dogs:

  1. mysql> SELECT * FROM pet WHERE species = 'dog' AND sex = 'f';
  2. +-------+--------+---------+------+------------+-------+
  3. | name  | owner  | species | sex  | birth      | death |
  4. +-------+--------+---------+------+------------+-------+
  5. | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  6. +-------+--------+---------+------+------------+-------+

The preceding query uses the AND logical operator. There is also an OR operator:

  1. mysql> SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';
  2. +----------+-------+---------+------+------------+-------+
  3. | name     | owner | species | sex  | birth      | death |
  4. +----------+-------+---------+------+------------+-------+
  5. | Chirpy   | Gwen  | bird    | f    | 1998-09-11 | NULL  |
  6. | Whistler | Gwen  | bird    | NULL | 1997-12-09 | NULL  |
  7. | Slim     | Benny | snake   | m    | 1996-04-29 | NULL  |
  8. +----------+-------+---------+------+------------+-------+

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:

  1. mysql> SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm')
  2.        OR (species = 'dog' AND sex = 'f');
  3. +-------+--------+---------+------+------------+-------+
  4. | name  | owner  | species | sex  | birth      | death |
  5. +-------+--------+---------+------+------------+-------+
  6. | Claws | Gwen   | cat     | m    | 1994-03-17 | NULL  |
  7. | Buffy | Harold | dog     | f    | 1989-05-13 | NULL  |
  8. +-------+--------+---------+------+------------+-------+

Zoek in de MySQL-handleiding

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 26/06/2006 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/mysql-rf-selecting-rows.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:en Manuel MySQL : https://dev.mysql.com/

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut