SELECT
DISTINCT (`os`.`inpost_machine`)
FROM
`order` `o`
INNER JOIN `order_shipment` `os` ON `os`.`order_id` = `o`.`id`
INNER JOIN `transport` `t` ON `t`.`id` = `o`.`transport_id`
INNER JOIN `transport_type` `tt` ON `tt`.`id` = `t`.`type_id`
WHERE
(`o`.`deleted_at` IS NULL)
AND (`o`.`website_id` = 5)
AND (`o`.`customer_id` = '10604984')
AND (`tt`.`code` = 'paczkomat')
ORDER BY
`o`.`created_at` DESC
LIMIT
1
SELECT
`inpost_machine`
FROM
(
SELECT
`os`.`inpost_machine`,
MAX(o.created_at)
FROM
`order` `o`
INNER JOIN `order_shipment` `os` ON `os`.`order_id` = `o`.`id`
INNER JOIN `transport` `t` ON `t`.`id` = `o`.`transport_id`
INNER JOIN `transport_type` `tt` ON `tt`.`id` = `t`.`type_id`
WHERE
(`o`.`deleted_at` IS NULL)
AND (`o`.`website_id` = 5)
AND (`o`.`customer_id` = '10604984')
AND (`tt`.`code` = 'paczkomat')
GROUP BY
`os`.`inpost_machine`
ORDER BY
MAX(o.created_at) DESC
) AS sub LIMIT 5