Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFreddie Kuhle
8,037 PointsSQL - How can I add a column from one table to my results from another table?
I'm working on the 3rd question in the SQL Playground - Stage 3 Practice questions after this video and need a bit of help: https://teamtreehouse.com/library/reporting-with-sql/aggregate-and-numeric-functions/practice-session
Is it possible for me to SELECT the 'title' column from the 'movies' table, and show it alongside the columns I SELECT from the 'reviews' table?
I'm looking to SELECT the 'title' column (from the 'movies' table), the 'movie_id' column ('reviews' table) and the average 'rating' column ('reviews' table).
The 'movie_id' column in the 'reviews' table matches with the 'id' column in the 'movies' table.
Thanks in advance!
1 Answer
Freddie Kuhle
8,037 PointsSolved it! With thanks to this page: https://stackoverflow.com/questions/20585010/sql-getting-a-column-from-another-table-to-join-this-query
For anyone that has the same problem in the future, here is the code I used:
SELECT movies.title AS title, reviews.movie_id AS movie_id, ROUND(AVG(reviews.rating), 1) AS average_rating FROM reviews JOIN movies ON movies.id = reviews.movie_id GROUP BY title;