[英]Getting Error 1052 When trying to join 3 tables together with inner join
I am having trouble using an inner join to join 3 tables together.我在使用内部连接将 3 个表连接在一起时遇到问题。 The tables are as follows.
表格如下。
mysql> SELECT * FROM tbldvdactors;
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;
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;
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. ASIN 列在多个表中定义,因此您必须明确选择一个。
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.在第一行,您应该指定从中选择字段 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.