错误:列';id';字段列表中的php mysqli不明确
我有两张桌子: 新闻: 标签: 关于结果:错误:列';id';字段列表中的php mysqli不明确,php,mysqli,Php,Mysqli,我有两张桌子: 新闻: 标签: 关于结果: ("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 L
("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
如何修复此错误?您需要别名。Yuo有两个表,都有列
id
。在选择中,您可以请求id
,而不指定需要哪一个
您需要在此处指定表格(在id
之前):
。。。(“选择id、title、front_thumbs、short…
您需要别名。您有两个表,都有列id
。在选择中,您请求id
,而不指定需要哪一个
您需要在此处指定表格(在id
之前):
…(“选择id、title、front_thumbs、short…
当两个表都有相同的字段名时,它会变得模棱两可并解决此问题
使用选择您正在使用的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)
当两个表都有相同的字段名时,就变得模棱两可,需要解决这个问题 使用选择您正在使用的
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)
你想要哪个
id
呢?news.id
或者tags.id
?你可以有一个或者两个,你只需要添加表名-SELECT news.id,
或者SELECT tags.id,
或者SELECT news.id,tags.id,
你想要哪个id
或者ags.id
?您可以有一个或两个,只需添加表名-SELECT news.id,…
或SELECT tags.id,…
或SELECT news.id,tags.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)