MIN() and MAX() in mysql returing wrong values?
-
I have a table in MYSQL to track movies. The two fields I am interested in at this time are mlength (INT) (entered in minutes i.e. 98) and Name. When I query to find the MIN time it works ok: SELECT MIN(length) FROM movie; If I add this: SELECT mname, MIN(length) FROM movie; I get the same movie name whether I use MIN or MAX and the movie name I get is neither the shortest or longest movie in the database. I would ultimatley like to query to find the longest AND shortest film in the database (in a single query). Any thoughts on the syntax here? It looks correct to me. Thanks.
-
Answer:
From what I understand you need to get either the name of the minimum or maximum entry length from the database? It'd be something more like: "SELECT mname FROM movie ORDER BY length ASC" That would output all of the movie names ordered by length. "I would ultimatley like to query to find the longest AND shortest film in the database (in a single query)." for this you would need something like: "SELECT name FROM movie WHERE length = (SELECT MAX(length) FROM movie) AND length = (SELECT MIN(length) FROM name) LIMIT 2"
Joe Smith at Yahoo! Answers Visit the source
Related Q & A:
- How to calculate max/min scales on a scatter plot?Best solution by Cross Validated
- Is it OK to increase validation checks and decrease min gradient while training neural network?Best solution by Cross Validated
- What is the bigest motor for a t-max?Best solution by Yahoo! Answers
- When is the max power event?Best solution by exhibitions.co.uk
- Is WiFi MAX Worth it?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.