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 trial

Databases

Ethan Martin
PLUS
Ethan Martin
Courses Plus Student 1,883 Points

Enter a review for E.T. Use a username and review of your choosing.

The scheme for reviews doesn't have a title column, only a column for the movie ID.

This task is asking me to insert a review into that data base for ET.

Say I didnt have the movie ID? Or I just didnt want to look it up just so I could insert the value appropriately into the reviews data base.

Is there some way to link the two tables and say "Insert a review for ET by inserting the id that the movie is linked to, then insert username, review, and rating?"

Maybe that's asking two much for one line of code. but I feel like there has to be a simpler way to accomplish this.

2 Answers

Here's an explanation from w3schools of INSERT INTO SELECT and an explanation of literals from geeksengine.com

INSERT INTO reviews (movie_id, username, review, rating)
SELECT movie_id, "my username", "my review", my rating
FROM movies
WHERE title = "E.T.";
Ethan Martin
Ethan Martin
Courses Plus Student 1,883 Points

If it wouldn't be too much trouble, could you break down in words what this is doing?