I have a SQL query that was working fine until we upgraded MySQL from version 5.5 to version 5.7. The SQL query should return the highest value of tx_id for each user. I don't understand why this query should return a different result now that MySQL has been upgraded. Am I using some quirk of SQL that returns values in an unspecified order (could "GROUP BY" be the culprit here?). I would like to understand what it is that I am doing that produces a different result.
This is my query:
SELECT t.tx_id FROM (
SELECT tx_id, NAME, ACTION
FROM employee
ORDER BY tx_id DESC) t
GROUP BY t.name
When running on version 5.5 the following is returned (correctly):
4 adam
6 bob
When running on version 5.7 however the following is returned:
3 adam
4 bob
And here is some sample data and the table definition if you wish to try it out:
CREATE TABLE `employee` (
`tx_id` int(10) DEFAULT NULL,
`name` varchar(50) DEFAULT NULL,
`action` int(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*Data for the table `employee` */
insert into `employee`(`tx_id`,`name`,`action`) values
(3,'adam',1),
(4,'adam',2),
(4,'bob',1),
(5,'bob',2),
(6,'bob',3);