SQL Counter and returner, doubles the result

混江龙づ霸主 提交于 2019-12-05 15:09:40

Basically you have 2 places to duplicate rows if your ASP is correct:

1) SQL is wrong (Probably you have to use DISTINCT operator)

2) C# code is wrong (Probably you have to check your data source)

Check your SQL pls. And share your C# code with us.

Use this

SELECT distinct  category_name, thread_category_id, threadCount
FROM
( SELECT categories.category_name, threads.thread_category_id, COUNT(*) 
                        AS 'threadCount' FROM threads 
                        INNER JOIN categories ON categories.category_id = threads.thread_category_id
                        GROUP BY categories.category_name, threads.thread_category_id ) A

Use Distinct .its remove all duplicated rows

SELECT DISTINCT(threads.thread_category_id), categories.category_name, COUNT(*) 
                        AS 'threadCount' FROM threads 
                        INNER JOIN categories ON categories.category_id = threads.thread_category_id
                        GROUP BY threads.thread_category_id
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!