Reputation: 15
I need to find the longest movie and only print the title of that movie. However, when I try to do it, it just prints the title of every movie and all their lengths. So i'd like to know what I am doing wrong.
SELECT m.movie_title, MAX(m.movie_len)
FROM movie m
GROUP BY m.movie_title;
Upvotes: 0
Views: 31
Reputation: 3108
you must have clause where to limit rows, or use your query as sub query or if your db engine support use "limit 1 like Gordon Linoff writ, or select top 1 like in sql-serwer, or first over like in oracle... you didn't write db engine name...
Upvotes: 0
Reputation: 1270463
One method uses order by
and limit
:
select m.*
from movie m
order by length desc
limit 1;
MAX()
is a function that operates on one column. It has no effect on other columns.
Upvotes: 2