Menu
Coddy logo textTech

Basic Join Part 2

Part of the Fundamentals section of Coddy's SQL journey — lesson 44 of 72.

Joins can also be used on tables that we create. To combine nested tables with joins we need to add AS to identify the nested query with a name.

For example:

SELECT table1.col1, table2.col2, ...
FROM table1, (SELECT * FROM table) AS table2
WHERE table1.id = table2.id
challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>grades</strong>: <strong>course_id</strong>, <strong>student_id</strong>, <strong>grade</strong>
  • <strong>students</strong>: <strong>id</strong>, <strong>name</strong>

Calculate for each student their average grade and return the name and the average grade for each.

Name the columns student, grade.

Round the average to 2 decimal places and sort the result by the average grade in ascending order.

Cheat sheet

To join tables with nested queries, use AS to name the nested query:

SELECT table1.col1, table2.col2, ...
FROM table1, (SELECT * FROM table) AS table2
WHERE table1.id = table2.id

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals