简体   繁体   English

字段列表中的列“ media_id”不明确

[英]Column 'media_id' in field list is ambiguous

Hi I am trying to get this sql query to work but I keep getting this error, just wondering if someone could point out to me what have I done wrong ? 嗨,我正在尝试使此sql查询工作,但我一直收到此错误,只是想知道是否有人可以向我指出我做错了什么?

My sql query 我的SQL查询

SELECT title,blurb,media_id
FROM media_career_crossref 
INNER JOIN media 
ON media.media_id = media_career_crossref.media_id

I have got a media table and also a media_career_crossref table. 我有一个媒体表,还有一个media_career_crossref表。 the media_id is in the media table the media_id column in the media_career_crossref ref is linked into this table hence the inner join media_id在媒体表中,media_career_crossref引用中的media_id列链接到该表中,因此内部联接

Could you explain why it is doing this ? 您能解释一下为什么这样做吗? and how I would prevent it from happening again. 以及如何防止它再次发生。

Both tables (media and media_career_crossref) have a column named media_id. 两个表(media和media_career_crossref)都有一个名为media_id的列。 In the SELECT statement, you must specify from which table you want to get the value from. 在SELECT语句中,您必须指定要从哪个表中获取值。 Eg 例如

SELECT title,blurb, media_career_crossref.media_id
FROM media_career_crossref 
INNER JOIN media 
ON media.media_id = media_career_crossref.media_id

Try prefixing the column. 尝试为列添加前缀。 engine must know from what table you want to get it 引擎必须知道要从哪个表中获取它

SELECT title,blurb,media.media_id
FROM media_career_crossref 
INNER JOIN media 
ON media.media_id = media_career_crossref.media_id

try it with an alias: 尝试使用别名:

SELECT title,blurb,m.media_id
FROM media_career_crossref mcc
INNER JOIN media m 
ON m.media_id = mcc.media_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM