I am having trouble using an inner join to join 3 tables together. The tables are as follows.
mysql> SELECT * FROM tbldvdactors;
ACTORID | FName | LName |
---|---|---|
1 | Val | Kilmer |
2 | Johnny | Depp |
3 | John | Cleese |
4 | Michael | Keaton |
5 | Roy | Scheider |
mysql> SELECT * FROM tbldvdtitles;
ASIN | Title | Price |
---|---|---|
6304711905 | Tombstone | 1.95 |
783229526 | Fear and Loathing in Las Vegas | 8.46 |
B00005O3VC | Monty Python and the Holy Grail | 8.88 |
B001CCIRG4 | Beetlejuice | 9.60 |
B007STBUHI | Jaws | 7.62 |
mysql> SELECT * FROM tblrelantionships;
ASIN | ACTORID |
---|---|
6304711905 | 1 |
783229526 | 2 |
B0000503VC | 3 |
B001CCIRG4 | 4 |
B007STBUHI | 5 |
Here is the command I am using
mysql> SELECT ASIN, Title, ACTOR_ID, FName, LName, Price
-> FROM tblrelantionships
-> INNER JOIN tbldvdtitles
-> ON tblrelantionships.ASIN = tbldvdtitles.ASIN
-> INNER JOIN tbldvdactors
-> ON tblrelantionships.ACTORID = tbldvdactors.ACTORID;
ERROR 1052 (23000): Column 'ASIN' in field list is ambiguous
Thanks in advance for any help you guys can provide.
The ASIN column is defined in more than one table, so you have to explicitly select one.
Using tables aliases makes query shorter and easier to read IMHO.
SELECT
tt.ASIN, tt.Title, ta.ACTOR_ID, ta.FName, ta.LName, tt.Price
FROM tblrelantionships tr
INNER JOIN tbldvdtitles tt
ON tr.ASIN = tt.ASIN
INNER JOIN tbldvdactors ta
ON tr.ACTORID = ta.ACTORID;
On the first line, you should specify the table from which you are selecting the field ANSI. Try this:
mysql> SELECT tblrelantionships.ASIN, Title, ACTOR_ID, FName, LName, Price
-> FROM tblrelantionships
-> INNER JOIN tbldvdtitles
-> ON tblrelantionships.ASIN = tbldvdtitles.ASIN
-> INNER JOIN tbldvdactors
-> ON tblrelantionships.ACTORID = tbldvdactors.ACTORID;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.