dammour
5/13/2019 - 3:30 PM

02 - Récupérer des informations avec SELECT

select * from wizard where birthday between '1975-01-01' and '1985-12-31' and is_muggle='0';

select * from wizard where firstname like 'H%';

select firstname, lastname from wizard where lastname='Potter' order by firstname;

select firstname, lastname, birthday from wizard order by birthday asc limit 0,1;

mysql> select * from wizard where birthday between '1975-01-01' and '1985-12-31' and is_muggle='0';
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+
| id | firstname | lastname | birthday   | birth_place | biography                             | is_muggle |
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+
|  1 | harry     | potter   | 1980-07-31 | london      |                                       |         0 |
|  2 | hermione  | granger  | 1979-09-19 |             | Friend of Harry Potter                |         0 |
|  4 | ron       | weasley  | 1980-03-01 |             | Best friend of Harry                  |         0 |
|  5 | ginny     | weasley  | 1981-08-11 |             | Sister of Ron and girlfriend of Harry |         0 |
|  6 | fred      | weasley  | 1978-04-01 |             |                                       |         0 |
|  7 | george    | weasley  | 1978-04-01 |             |                                       |         0 |
| 10 | drago     | malefoy  | 1980-06-05 |             |                                       |         0 |
+----+-----------+----------+------------+-------------+---------------------------------------+-----------+
7 rows in set (0,00 sec)

mysql> select * from wizard where firstname like 'H%';
+----+-----------+----------+------------+-------------+------------------------+-----------+
| id | firstname | lastname | birthday   | birth_place | biography              | is_muggle |
+----+-----------+----------+------------+-------------+------------------------+-----------+
|  1 | harry     | potter   | 1980-07-31 | london      |                        |         0 |
|  2 | hermione  | granger  | 1979-09-19 |             | Friend of Harry Potter |         0 |
+----+-----------+----------+------------+-------------+------------------------+-----------+
2 rows in set (0,00 sec)

mysql> select firstname, lastname from wizard where lastname='Potter' order by firstname;
+-----------+----------+
| firstname | lastname |
+-----------+----------+
| harry     | potter   |
| lily      | potter   |
+-----------+----------+
2 rows in set (0,00 sec)

mysql> select firstname, lastname, birthday from wizard order by birthday asc limit 0,1;
+-----------+------------+------------+
| firstname | lastname   | birthday   |
+-----------+------------+------------+
| albus     | dumbledore | 1881-07-01 |
+-----------+------------+------------+
1 row in set (0,00 sec)