Error
Errors:
Description
Select the first names and house id’s for each member of the Patil family.
Test Cases
Pass | Test | Message | |
---|---|---|---|
- | Test results will show here. | - |
Errors:
5 points
Select the first names and house id’s for each member of the Patil family.
Here is what the database looks like
House
id | name |
---|---|
1 | Gryffindor |
2 | Hufflepuff |
3 | Ravenclaw |
4 | Slytherin |
Person
id | first_name | last_name | house |
---|---|---|---|
1 | Euan | Abercrombie | 1 |
2 | Katie | Bell | 1 |
3 | Sirius | Black | 1 |
4 | Lavender | Brown | 1 |
5 | Ritchie | Coote | 1 |
6 | Colin | Creevey | 1 |
7 | Dennis | Creevey | 1 |
8 | Albus | Dumbledore | 1 |
9 | Seamus | Finnigan | 1 |
10 | Hermione | Granger | 1 |
11 | Rubeus | Hagrid | 1 |
12 | Angelina | Johnson | 1 |
13 | Lee | Jordan | 1 |
14 | Andrew | Kirke | 1 |
15 | Neville | Longbottom | 1 |
16 | Remus | Lupin | 1 |
17 | Natalie | McDonald | 1 |
18 | Mary | Macdonald | 1 |
19 | Minerva | McGonagall | 1 |
20 | Cormac | McLaggen | 1 |
21 | Parvati | Patil | 1 |
22 | Jimmy | Peakes | 1 |
23 | Peter | Pettigrew | 1 |
24 | Harry | Potter | 1 |
25 | James | Potter | 1 |
26 | Lily | Potter | 1 |
27 | Demelza | Robins | 1 |
28 | Jack | Sloper | 1 |
29 | Alicia | Spinnet | 1 |
30 | Dean | Thomas | 1 |
31 | Romilda | Vane | 1 |
32 | Arthur | Weasley | 1 |
33 | Bill | Weasley | 1 |
34 | Charlie | Weasley | 1 |
35 | Fred | Weasley | 1 |
36 | George | Weasley | 1 |
37 | Ginny | Weasley | 1 |
38 | Molly | Weasley | 1 |
39 | Percy | Weasley | 1 |
40 | Ron | Weasley | 1 |
41 | Oliver | Wood | 1 |
42 | Hannah | Abbott | 2 |
43 | Susan | Bones | 2 |
44 | Eleanor | Branstone | 2 |
45 | Owen | Cauldwell | 2 |
46 | Cedric | Diggory | 2 |
47 | Justin | Finch-Fletchley | 2 |
48 | Ernie | Macmillan | 2 |
49 | Laura | Madley | 2 |
50 | Eloise | Midgeon | 2 |
51 | Zacharias | Smith | 2 |
52 | Pomona | Sprout | 2 |
53 | Nymphadora | Tonks | 2 |
54 | Kevin | Whitby | 2 |
55 | Rose | Zeller | 2 |
56 | Stewart | Ackerley | 3 |
57 | Marcus | Belby | 3 |
58 | Terry | Boot | 3 |
59 | Mandy | Brocklehurst | 3 |
60 | Cho | Chang | 3 |
61 | Eddie | Carmichael | 3 |
62 | Penelope | Clearwater | 3 |
63 | Michael | Corner | 3 |
64 | Roger | Davies | 3 |
65 | Marietta | Edgecombe | 3 |
66 | S | Fawcett | 3 |
67 | Filius | Flitwick | 3 |
68 | Anthony | Goldstein | 3 |
69 | Luna | Lovegood | 3 |
70 | Padma | Patil | 3 |
71 | Orla | Quirke | 3 |
72 | Lisa | Turpin | 3 |
73 | Malcolm | Baddock | 4 |
74 | Regulus | Black | 4 |
75 | Miles | Bletchley | 4 |
76 | Millicent | Bullstrode | 4 |
77 | Vincent | Crabbe | 4 |
78 | Marcus | Flint | 4 |
79 | Gregory | Goyle | 4 |
80 | Terence | Higgs | 4 |
81 | Bellatrix | Lestrange | 4 |
82 | Rabastan | Lestrange | 4 |
83 | Rodolphus | Lestrange | 4 |
84 | Abraxas | Malfoy | 4 |
85 | Draco | Malfoy | 4 |
86 | Lucius | Malfoy | 4 |
87 | Narcissa | Malfoy | 4 |
88 | Theodore | Nott | 4 |
89 | Pansy | Parkinson | 4 |
90 | Graham | Pritchard | 4 |
91 | Adrian | Pucey | 4 |
92 | Tom | Riddle | 4 |
93 | Horace | Slughorn | 4 |
94 | Severus | Snape | 4 |
95 | Blaise | Zabini | 4 |
96 | Godric | Gryffindor | 1 |
97 | Helga | Hufflepuff | 2 |
98 | Rowena | Ravenclaw | 3 |
99 | Salazar | Slytherin | 4 |
SQL Documentation
Selecting from a table.
SELECT * FROM Table;
Selecting only certain fields from a table.
SELECT field1, field2 FROM Table;
WHERE clauses.
-- Basic WHERE clause SELECT * FROM Table WHERE condition; -- Compound WHERE clauses SELECT * FROM Table WHERE condition1 AND condition2;
Condition operators
= equal < less than > greater than <> not equal IN (a, b, c) Value is in a list BETWEEN x AND y Value is between x and y LIKE "%" String matches a pattern
String patterns.
"A%" (words starting with "A") "%a" (words ending with "a") "%a%" (words with "a" in it)
Ordering / Sorting queries.
// Sort by a field name ORDER BY field_name; -- Sort by a field name in reverse ORDER BY field_name DESC; -- Sort by a field and then sort by a 2nd field when the 1st field is equal ORDER BY field_1, field_2;
Renaming fields in results
SELECT field_name AS "Field Name" SELECT first_name AS "First Name"
Joining Tables.
-- Select all fields in both tables combined. SELECT * FROM TableA JOIN TableB; -- Select only the rows in the joined table where the ids match SELECT * FROM TableA JOIN TableB WHERE TableA.id = TableB.id; -- Select only the relevant columns from each table -- Where their ids match SELECT TableA.value, TableB.value FROM TableA JOIN TableB WHERE TableA.id = TableB.id;
The COUNT Function
-- Return the number of rows in Table SELECT COUNT(*) FROM Table; -- Return the number of houses and name -- the column "Num Houses" SELECT COUNT(*) As "Num Houses" FROM House;
Grouping
-- Syntax for grouping and counting SELECT field_name, COUNT(*) FROM Table GROUP BY field_name;
Filtering with HAVING
-- You use HAVING instead of WHERE if you are -- filtering after a GROUP BY SELECT field_name, COUNT(*) FROM Table GROUP BY field_name HAVING condition;
Limiting results
-- Use LIMIT after any query to limit the number of results SELECT * FROM Table LIMIT 10; -- Ex) Show the 5 highest values only SELECT field_name, COUNT(*) FROM Table GROUP BY field_name ORDER BY COUNT(*) DESC LIMIT 5;