Reputation: 300
How can I make a select statement that will allow me to get the distinct words with its corresponding count but the count retrieved has to be the largest value.
For context My table has 3 columns: word, count, url
I go through a bunch of urls and count the occurrences of each word on a page. Both the word and url columns make up a composite primary key.
Not that I will count biology twice, as long as it comes from two different links. That's why it is important I only return one occurrence of the word with its highest count. Any input appreciated.
Upvotes: 0
Views: 31
Reputation: 1507
Try this:
SELECT * FROM YourTable
INNER JOIN (SELECT word, MAX(count) AS maxCount FROM YourTable GROUP BY word) t
ON t.maxCount = YourTable.count AND t.word = Yourtable.word
Upvotes: 0
Reputation: 13517
You can try below query -
SELECT WORD, MAX(COUNT), URL
FROM YOUR_TABLE
GROUP BY WORD
Hope this helps.
Upvotes: 0