I have the table for messages like this:
CREATE TABLE `message` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`from_id` bigint(20) unsigned NOT NULL,
`to_id` bigint(20) unsigned NOT NULL,
`body` text COLLATE utf8mb4_unicode_ci NOT NULL,
`status` tinyint(4) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
and try to select each last message from userX to userY, but mysql always says that I have nonaggregated columns (without only_full_group_by its work well). How I can select this in strict mode? Not working query for example :
select
t1.created_at,
t1.from_id,
t1.to_id,
t1.body,
t1.status,
( select created_at from test1.message where from_id = t1.from_id order by created_at desc limit 1 ) as last_timestamp
from test1.message as t1
group by t1.from_id
having t1.created_at = last_timestamp