0

I am trying to pull multiply pieces from information from a range of tables. i will present a less complex problem, which in fact represents a much larger functionality/ query

I have winning_category, review, review_like tables.

winning_category = category_id, category_name, id
review = id, header
review_like = id, review_id

I will first present a query that works for gathering like count, share count, view count, review.* from these 5 tables

SELECT COUNT(DISTINCT a_like.article_like_id) AS likecount, a.* FROM article AS a 
LEFT JOIN article_like AS a_like ON a.id = a_like.article_id 
WHERE a.created_date BETWEEN '2017-07-01 00:00:00' AND '2017-08-01 00:00:00'
GROUP BY a.id 
ORDER BY  likecount 
DESC OFFSET 0 LIMIT 10 

Now here we have my question

SELECT 
        COUNT(DISTINCT r_like.review_like_id) AS likecount,
        r.header AS r_header,
        w.category_name

FROM review AS r
LEFT JOIN review_like AS r_like ON r.id = r_like.review_id 
LEFT JOIN winning_category AS w ON r.id = w.category_id 
WHERE r.id = w.category_id
GROUP BY r.id
ORDER BY  likecount;

It says ""w.category_name" must appear in the GROUP BY clause or be used in an aggregate function"....

I have read this post here and many similar ones which do not have what I need

Any tips will be well received

0 Answers0