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 trialAnthony Bilotti
4,332 PointsSQL Error: Ambiguous Column Name: media_id
I was trying to join two tables together when I got the error SQL Error: Ambiguous Column Name: media_id. I do not know what happened! Please help me!
Code Attached
2 Answers
Steven Parker
231,261 PointsThat error probably indicates that both tables have a column named media_id. Just put the table name that you want to select the column from and a period in front of the column name.
For example, if the table name was foo, you might have a query that starts like this:
SELECT foo.media_id ...
Jessica Murillo
9,119 PointsI had the same problem. Steven Parker was right. Since there are two tables with the column name media_id it does know what table to pull that column from so you have to add Media before media_id in the SELECT statement. It worked for me after adding it.
SELECT Media.media_id, title, category, img, format, year, genre, publisher, isbn
FROM Media
JOIN Genres ON Media.genre_id = Genres.genre_id
LEFT OUTER JOIN Books ON Media.media_id = Books.media_id
WHERE Media.media_id = $id;
Jessica Murillo
9,119 PointsI know this was a few months ago too but I am sure that other people will have this same problem.
jcorum
71,830 Pointsjcorum
71,830 PointsAnthony, you say "Code Attached" but I don't see any.