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.idChallenge
EasyAvailable 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.idTry it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns