CREATE TABLE IF NOT EXISTS `order_order_status` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`order_status_id` int(11) NOT NULL,
`order_id` int(11) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `order_order_status_order_status_id_index` (`order_status_id`),
KEY `order_order_status_order_id_index` (`order_id`),
KEY `order_order_status_created_at_index` (`created_at`),
KEY `order_order_status_updated_at_index` (`updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;
--
-- Dumping data for table `order_order_status`
--
INSERT INTO `order_order_status` (`id`, `order_status_id`, `order_id`, `created_at`, `updated_at`) VALUES
(1, 2, 1, '2016-10-01 01:57:37', '2016-10-01 01:57:37'),
(2, 2, 2, '2016-10-01 01:57:54', '2016-10-01 01:57:54'),
(3, 2, 3, '2016-10-02 02:12:49', '2016-10-02 02:12:49'),
(4, 6, 3, '2016-10-02 02:14:19', '2016-10-02 02:14:19');
What i want to select is:
1, 2, 1, '2016-10-01 01:57:37', '2016-10-01 01:57:37'
2, 2, 2, '2016-10-01 01:57:54', '2016-10-01 01:57:54'
4, 6, 3, '2016-10-02 02:14:19', '2016-10-02 02:14:19'
that is the newest entry of order_order_status grouped by order_id
now the problem:
running
select *, max(created_at) from `order_order_status` group by `order_order_status`.`order_id`
returns me:
or in prosa
it returns me NOT the newest entry, instead it returns the older one for order_id 3