I have the following table
Table structure:
CREATE TABLE IF NOT EXISTS `people` (
`name` varchar(10) NOT NULL,
`age` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Insert some values:
INSERT INTO `people` (`name`, `age`) VALUES
('bob', 13),
('john', 25),
('steve', 8),
('sue', 13);
Executed Query:
SELECT MAX( `age` ) , `name` FROM `people` WHERE 1
Expected Result:
25, John
Generated Result
25, bob
We can achieve this by using this query
SELECT `age`, `name` FROM `people` ORDER BY age DESC LIMIT 1
Question 1 : What I made mistake here and why this MAX function is not return the relevant row information?
Question 2: Which one is good to use, to increase performance MAX function or ORDER BY clause?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…