0% found this document useful (0 votes)
13 views8 pages

SQL Two Tables

The document provides SQL practice exercises using data from the 2022 Olympics and Pokemon. It includes tasks for retrieving and manipulating data from multiple tables, such as displaying athletes and medal counts, and filtering by specific criteria. Additionally, it includes reflection questions for self-assessment of understanding the material.

Uploaded by

oliwiadziwota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

SQL Two Tables

The document provides SQL practice exercises using data from the 2022 Olympics and Pokemon. It includes tasks for retrieving and manipulating data from multiple tables, such as displaying athletes and medal counts, and filtering by specific criteria. Additionally, it includes reflection questions for self-assessment of understanding the material.

Uploaded by

oliwiadziwota
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

SQL Practice – Getting Data from

Multiple tables
Here is a set of data from the 2022 Olympics in Beijing

Table Name: Countries

ID Country Continent Men Women Total


Athletes Athletes Athletes
NOR Norway Europe 53 31 84
GER Germany Europe 96 49 145
CHN People's Republic of China Asia 94 86 180
USA United States North America 118 108 226
SWE Sweden Europe 62 59 121
NED Netherlands Europe 21 20 41
AUT Austria Europe 62 42 104
SUI Switzerland Europe 92 75 167
ROC Russian Olympic Committee Europe/Asia 110 104 214
FRA France Europe 50 36 86

Table name: Results

ID Gold Silver Bronze


NOR 16 8 13
GER 12 10 5
CHN 9 4 2
USA 8 10 7
SWE 8 5 5
NED 8 5 4
AUT 7 7 4
SUI 7 2 5
ROC 6 12 14
FRA 5 7 2
1. Complete the SQL statement to show the country and number of
gold medals. Order the results smallest to largest by number of
Women Athletes

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

Use this as a model to help you complete the following questions

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

TIP: Put your SELECT, FROM, WHERE, ORDERBY on a separate row

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

TIP: Put your SELECT, FROM, WHERE, ORDERBY on a separate row

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

TIP: Put your SELECT, FROM, WHERE, ORDERBY on a separate row


Answer the following questions honestly and use it as an
opportunity to reflect on your own work.

Circle the appropriate response:

1. I have a good understanding of this material

Strongly
Disagree Agree Strongly Agree
Disagree

2. I know where to go to get help

Strongly
Disagree Agree Strongly Agree
Disagree

3. I know what I need to do to improve my skill in this area

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:

Table Name: Pokemon

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

Table Name: Type

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

TIP: Put your SELECT, FROM, WHERE, ORDERBY on a separate row

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

TIP: Put your SELECT, FROM, WHERE, ORDERBY on a separate row


3. Write the SQL statement select the ID, name and Type1 of all the
pokemon who have are NOT a type 1 Bug.

TIP: Put your SELECT, FROM, WHERE, ORDERBY on a separate row

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

TIP: Put your SELECT, FROM, WHERE, ORDERBY on a separate row


5. Write the SQL statement select the name, Type1 and Type 2 of all
the pokemon. Display in ascending order by Pokemon ID

TIP: Put your SELECT, FROM, WHERE, ORDERBY on a separate row

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.

TIP: Put your SELECT, FROM, WHERE, ORDERBY on a separate row

You might also like