SQL Two Tables
SQL Two Tables
Multiple tables
Here is a set of data from the 2022 Olympics in Beijing
Women athletes
Countries.country, Countries, results
DESC
results.Gold
Countries.ID =
Goals > 86 Olympics, results
Results.ID
Countries.country = Countries.Womenathle Countries.country,
Results.country tes ASC results.Bronze
SELECT
FROM
WHERE
ORDER
BY
SELECT tablename.fieldname
FROM tablename1, tablename2
WHERE criteria AND table1.foreignkey = table2.primarykey
ORDER BY tablename.fieldname ASC | DESC
2. Write the SQL statement to display the total number of athletes and
the number of gold medals. Order the results alphabetically by
Continent
3. Write the SQL statement to display the total number of athletes and
the number of gold, silver and bronze medals. Order the results
alphabetically by Continent
4. Write the SQL statement to display the country, number of men and
women and the number bronze medals. Order the results largest to
smallest by number of bronze medals
Strongly
Disagree Agree Strongly Agree
Disagree
Strongly
Disagree Agree Strongly Agree
Disagree
Strongly
Disagree Agree Strongly Agree
Disagree
What down one thing from this task that you will ensure you will
remember to do moving forward.
SQL Practice – Getting Data from
Multiple tables (More Practice)
Here is a new set of data. This one is on Pokemon, there are two tables:
PokemonI
Name Type 1 Type 2 Total
D
44 Gloom 1 6 395
45 Vileplume 1 6 490
46 Paras 4 1 285
47 Parasect 4 1 405
48 Venonat 4 6 305
49 Venomoth 4 6 450
50 Diglett 8 265
51 Dugtrio 8 405
56 Mankey 5 305
57 Primeape 5 455
58 Growlithe 2 350
59 Arcanine 2 555
66 Machop 5 305
67 Machoke 5 405
68 Machamp 5 505
69 Bellsprout 1 6 300
70 Weepinbell 1 6 390
71 Victreebel 1 6 490
74 Geodude 7 8 300
TypeID Type
1 Grass
2 Fire
3 Water
4 Bug
5 Fighting
6 Poison
7 Rock
8 Ground
1. Write the SQL statement select all the fields of all the Type 1 Grass
pokemon, display the results in ascending order by Total
2. Write the SQL statement select the name and total of all the
pokemon who have a type of "ground" (either Type 1 OR Type 2)
display the results in reverse alphabetical order by name
4. Write the SQL statement select the ID, name and Type1 of all the
pokemon who have are a type 2 Poison and have a total between
300 and 400. Order the results from highest to lowest by Type 1
6. Write the SQL statement select the name and total fields of all the
pokemon that start with the letter "G" and have a type 1 of either
grass or fire. Order the results from highest to lowest by total.