Mysql 计算列和内部联接另一个表时出错

Mysql 计算列和内部联接另一个表时出错,mysql,count,inner-join,Mysql,Count,Inner Join,我想数一数评论最多的新闻。我有两个表:comments和news,它们包含相同的列:news\u ID select *,count(News_ID) as count from comments inner join news where comments.News_ID = news.News_ID group by comments.News_ID order by count DESC limit 4 我得到这个错误 #1052 - Column 'News_ID' in field

我想数一数评论最多的新闻。我有两个表:comments和news,它们包含相同的列:news\u ID

select *,count(News_ID) as count from comments inner join news where comments.News_ID = news.News_ID group by comments.News_ID order by count DESC limit 4
我得到这个错误

#1052 - Column 'News_ID' in field list is ambiguous

这是否意味着我要数一数的专栏?

确保你说出你选择的专栏中的
news\u id
<代码>评论。新闻id,或
新闻。新闻id

select 
    *,
    count(comments.News_ID) as count 
from comments 
inner join news where comments.News_ID = news.News_ID 
group by comments.News_ID 
order by count DESC limit 4

您需要告诉在select中使用其列的表的名称有两个
News\u ID
列,因此在查询选择哪个表的列时,要考虑其不明确性,还需要为join with on子句使用正确的语法

select n.*,c.*,count(n.News_ID) as count 
from comments c
inner join news n ON(c.News_ID = n.News_ID)
 group by c.News_ID 
order by count DESC limit 4

当然我以前做过lol。如果有多个列从不同的表中调用相同的东西,则必须指定要拉出的列:)