0

I have a table called "Reviews" which contains the review ID and the content of the review.

In order to count how many reviews contain a particular keyword, I have used the code.

SELECT COUNT(text)
FROM Reviews
WHERE text LIKE '%PC%';

Now, what I'm trying to do is instead of "%PC%", I get the keyword from another table which contains a keyword ID and the actual keyword.

With all that I hope the results will be like:

COUNT(text) | Keyword
    5       |   PC
    1       |   Computer

The count being the number of reviews which contained the particular keyword.

Thanks in advance.

2 Answers 2

0

Use the GROUP BY function:

    SELECT COUNT(text), text as Keyword
    FROM Reviews
-- you can use where clause here to filter down your results further
    GROUP BY text;
0

Try this

SELECT k.keyword, COUNT(text) cnt
FROM KeywordTable k
LEFT OUTER JOIN Reviews r ON r.text like '%' + k.Keyword + '%'
GROUP BY k.keyword
2
  • This is what I'm trying to achieve, but that code only returns 0's. Apr 14, 2013 at 21:54
  • can you post data from your tables?
    – rs.
    Apr 14, 2013 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.