I have a schema as follows:
CREATE TABLE `a` (
`id` char(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`c_id` char(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`d_id` char(32) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO a VALUES ('1673b492fe9049a5bda9dcea56e9de6a', '1673b49303d04aadba461c27726f8cb8', '16328bc433604fe0af1329a0c2bc0312');
INSERT INTO a VALUES ('163b75aeafe0479aa426e506c687da91', '1673b49303d04aadba461c27726f8cb8', '15fbace119504b1db81bb6409b77fb26');
INSERT INTO a VALUES ('161ad54eb7f042c584881ed6dec31e68', '16328bc433604fe0af1329a0c2bc0312', '160705a0b0304a02b00ec47c2c84f99b');
I require a query which basically looks like
select c_id, max(id), d_id from a group by c_id
, in which the data is coming from the row which matches MAX(id)
Of course, this is not possible in the SQL mode which allows only full group by:
Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a.d_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Is this possible, and how do I do it? Preferably without a join.