Really stumped here, so any advice would be much appreciated please.
I in the clients table, I have the following records for the client with ID = 257:
SELECT ref, ID, client_name, data_1 FROM clients WHERE ID = 257
+------+-----+-------------+--------+
| ref | ID | client_name | data_1 |
+------+-----+-------------+--------+
| 1123 | 257 | Client257 | 0 |
| 1124 | 257 | Client257 | 163 |
+------+-----+-------------+--------+
Now, if I add a simple MAX() to the ref field, I get:
SELECT MAX(ref), ID, client_name, data_1 FROM clients WHERE ID = 257
+------+-----+-------------+--------+
| ref | ID | client_name | data_1 |
+------+-----+-------------+--------+
| 1124 | 257 | Client257 | 0 |
+------+-----+-------------+--------+
I should get:
+------+-----+-------------+--------+
| ref | ID | client_name | data_1 |
+------+-----+-------------+--------+
| 1124 | 257 | Client257 | 163 |
+------+-----+-------------+--------+
Can anyone explain this please? And what should I do to get the desired result?
EDIT:
Added the output of SHOW CREATE TABLE clients as requested by @Ilion:
CREATE TABLE `clients` (
`ref` int(11) unsigned NOT NULL AUTO_INCREMENT,
`ID` int(11) unsigned NOT NULL,
`client_name` varchar(75) DEFAULT NULL,
`data_1` int(11) unsigned NOT NULL DEFAULT '0',
`last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY `ref` (`ref`)
) ENGINE=MyISAM AUTO_INCREMENT=1135 DEFAULT CHARSET=utf8
does this help?