我有两张桌子:
消息:
|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
如何修复此错误?
答案 0 :(得分:0)
你需要别名。 Yuo有2个表,列id
。在您的选择中,您请求id
,而不指定您需要哪一个。
您需要在此处指定表格(id
之前):
... ("SELECT id,title,front_thumbs,short ...
答案 1 :(得分:0)
当两个表具有相同的字段名称时,它会变得模棱两可并解决此问题
使用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)