我有两个表:
新闻:|id|title|image|timestamp|....
标记:
|id|books_id|...
结果:("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)
但是我看到这个错误:
Error: Column 'id' in field list is ambiguous
如何修复这个错误?
当两个表有相同的字段名时,它会变得模棱两可,并且要解决这个问题使用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)
您需要别名。您有2个表都列id
。在你的select中,你请求id
,而没有指定你需要它们中的哪一个。
你需要在这里指定table(在id
之前):
... ("SELECT id,title,front_thumbs,short ...