Created
May 21, 2019 08:33
-
-
Save santiagocodes/d019462617d7da1619406f016ff8780b to your computer and use it in GitHub Desktop.
SQL02- Retriving information with SELECT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Retrieving wizards Challenge from https://images.innoveduc.fr/bdd/data2.sql | |
Retrieve all the fields for wizards born between 1975 and 1985... | |
mysql> SELECT * FROM wizard WHERE birthday BETWEEN '1975-01-01' AND '1985-12-31'; | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`, `birthday`, `birth_place`, `biography`, `is_muggle`) VALUES | |
('harry', 'potter', '1980-07-31', 'london', '', '0'); | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`, `birthday`, `birth_place`, `biography`, `is_muggle`) VALUES | |
('hermione', 'granger', '1979-09-19', '', 'Friend of Harry Potter', '0'); | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`, `birthday`, `birth_place`, `biography`, `is_muggle`) VALUES | |
('ron', 'weasley', '1980-03-01', '', 'Best friend of Harry', '0'); | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`, `birthday`, `birth_place`, `biography`, `is_muggle`) VALUES | |
('ginny', 'weasley', '1981-08-11', '', 'Sister of Ron and girlfriend of Harry', '0'); | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`, `birthday`, `birth_place`, `biography`, `is_muggle`) VALUES | |
('fred', 'weasley', '1978-04-01', '', '', '0'); | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`, `birthday`, `birth_place`, `biography`, `is_muggle`) VALUES | |
('george', 'weasley', '1978-04-01', '', '', '0'); | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`, `birthday`, `birth_place`, `biography`, `is_muggle`) VALUES | |
('drago', 'malefoy', '1980-06-05', '', '', '0'); | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`, `birthday`, `birth_place`, `biography`, `is_muggle`) VALUES | |
('dudley', 'dursley', '1980-06-23', '', 'Cousin d\'Harry', '1'); | |
Only the wizards’ names whose first names start with the letter “H”... | |
mysql> SELECT firstname FROM wizard WHERE firstname LIKE 'h%'; | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`) VALUES | |
('harry'); | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`) VALUES | |
('hermione'); | |
The first name and last names of the whole “Potter” family, sorted by first name order... | |
mysql> SELECT firstname, lastname FROM wizard WHERE lastname='potter' ORDER BY firstname ASC; | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`) VALUES | |
('harry', 'potter'); | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`) VALUES | |
('lily', 'potter'); | |
The oldest wizard’s first name, last name and birth date (must work regardless of the table content)... | |
mysql> SELECT firstname, lastname, birthday AS birth_date FROM wizard ORDER BY birthday ASC LIMIT 1; | |
INSERT INTO `wild_db_quest`.`wizard` (`firstname`, `lastname`, `birthday`) VALUES | |
('albus', 'dumbledore', '1881-07-01'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment