0

I have this query:

SELECT tag, filename, timecode, COUNT(tag) AS total 
FROM dados 
WHERE dados.tag = 'movie' 
AND dados.filename = 'movie2.mp4' 
GROUP BY timecode

And this is the result:

But i only want the 3rd row, more precisely the timecode=2 because it's the most consisting tag with the higher value. How can i grab the highest value of timecode from those rows?

1 Answer 1

0

Use ORDER BY with LIMIT

SELECT tag, filename, timecode, COUNT(tag) AS total 
FROM dados 
WHERE dados.tag = 'movie' 
AND dados.filename = 'movie2.mp4' 
GROUP BY timecode
ORDER BY COUNT(tag) DESC
LIMIT 1
5
  • I'm not sure if limit will work together with group by. If limit works, I would sugest to add a 'limit 1' Aug 24, 2012 at 21:33
  • If you use it with LIMIT it will do what you need
    – John Conde
    Aug 24, 2012 at 21:34
  • He wants the row with the highest COUNT(tag), not highest timecode. Aug 24, 2012 at 21:35
  • If i use the limit like John said it will print this: 'movie', 'movie2.mp4', '6', '3'
    – zppinto
    Aug 24, 2012 at 21:36
  • Change it to ORDER BY COUNT(tag) DESC. Aug 24, 2012 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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