MySQL - how to use having in group by (SQL query)
The query has GROUP BY w.word so the COUNT(DISTINCT w.word) is - has to be - 1 for every group, so for every row in the results.

To get the results you want, you need to first GROUP BY product and then GROUP BY words:

SELECT g.words, 
       g.wordcount, 
       COUNT(*) AS productcount
FROM
    ( SELECT GROUP_CONCAT(DISTINCT w.word) AS words, 
             COUNT(DISTINCT w.word) AS wordcount
      FROM productwords pw JOIN words w ON pw.wordid = w.id 
      WHERE w.word IN ('lenovo', 'laptop', 'computer') 
      GROUP BY pw.productid
      -- HAVING COUNT(DISTINCT w.word) &gt;= 2
    ) AS g
GROUP BY g.words, g.wordcount ;