[英]Error: Column 'id' in field list is ambiguous php mysqli
I have two table : 我有两个表:
news: 新闻:
|id|title|image|timestamp|....
tags: 标签:
|id|books_id|...
for result: 结果:
("SELECT id,title,front_thumbs,short_desc,timestamp,counter,author,
FROM " . NEWS . " LEFT JOIN " . TAGS . " ON " NEWS . ".id = " . TAGS . ".content_id WHERE
" . TAGS . ".tags_id = ? AND approved = 1 ORDER BY timestamp DESC LIMIT 10", $id)
but I see this error: 但我看到这个错误:
Error: Column 'id' in field list is ambiguous
how do fix this error? 如何解决此错误?
You need alias. 您需要别名。 Yuo have 2 tables both with column
id
. Yuo有2个表,每个表的列
id
。 In your select you request id
without specifying which of them you need. 在您选择的情况下,您请求
id
而不指定您需要的id
。
You need to specify table here (before id
): 您需要在此处指定表格(在
id
之前):
... ("SELECT id,title,front_thumbs,short ...
When both tables have same field name it gets ambiguous and to solve this use SELECT NEWS.id
or TAGS.id
which table's id
you are using: 当两个表具有相同的字段名称时,它会变得模棱两可,要解决此问题,请使用SELECT
NEWS.id
或TAGS.id
,您正在使用哪个表的id
:
"SELECT NEWS.id,title,front_thumbs,short_desc,timestamp,counter,author,
FROM " . NEWS . " LEFT JOIN " . TAGS . " ON " NEWS . ".id = " . TAGS . ".content_id WHERE
" . TAGS . ".tags_id = ? AND approved = 1 ORDER BY timestamp DESC LIMIT 10", $id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.