Skip to content

Instantly share code, notes, and snippets.

@AmauryLugdu
Created November 19, 2019 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmauryLugdu/e10847fa9e5b57861864772088fd1d0f to your computer and use it in GitHub Desktop.
Save AmauryLugdu/e10847fa9e5b57861864772088fd1d0f to your computer and use it in GitHub Desktop.
02 - Retrieving information with SELECT
mysql> USE wild_db_quest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SELECT firstname,lastname,birthday,birth_place,biography,is_muggle FROM wizard WHERE birthday BETWEEN '1975-01-01' AND '1985-12-31';
+-----------+----------+------------+-------------+---------------------------------------+-----------+
| firstname | lastname | birthday | birth_place | biography | is_muggle |
+-----------+----------+------------+-------------+---------------------------------------+-----------+
| harry | potter | 1980-07-31 | london | | 0 |
| hermione | granger | 1979-09-19 | | Friend of Harry Potter | 0 |
| ron | weasley | 1980-03-01 | | Best friend of Harry | 0 |
| ginny | weasley | 1981-08-11 | | Sister of Ron and girlfriend of Harry | 0 |
| fred | weasley | 1978-04-01 | | | 0 |
| george | weasley | 1978-04-01 | | | 0 |
| drago | malefoy | 1980-06-05 | | | 0 |
| dudley | dursley | 1980-06-23 | | Cousin d'Harry | 1 |
+-----------+----------+------------+-------------+---------------------------------------+-----------+
8 rows in set (0,00 sec)
mysql> SELECT firstname FROM wizard WHERE firstname LIKE 'h%';
+-----------+
| firstname |
+-----------+
| harry |
| hermione |
+-----------+
2 rows in set (0,00 sec)
mysql> SELECT firstname,lastname FROM wizard WHERE lastname='potter' ORDER BY firstname ASC;
+-----------+----------+
| 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment