SELECT `t`.*
FROM (
SELECT MAX(`UpdateDate`) AS `last`, `OrgPropertTypeId`
FROM `table` AS `t`
WHERE `OrganizationId` = :organizationId
GROUP BY `OrgPropertTypeId`
) AS `l`
JOIN `table` AS `t` ON `t`.`OrganizationId` = :organizationId
AND `t`.`OrgPropertTypeId` = `l`.`OrgPropertTypeId`
AND `t`.`UpdateDate` = `l`.`last`
SELECT `a`.`id` AS `id`, `a`.`name` AS `name`,
`color`.`value` AS `color`, `weight`.`value` AS `weight`
FROM `a`
LEFT JOIN `b` AS `color` ON `b`.`a_id` = `a`.`id` AND `b`.`name` = 'color'
LEFT JOIN `b` AS `weight` ON `b`.`a_id` = `a`.`id` AND `b`.`name` = 'weight'
SELECT `h`.*, `h1`.`author`
FROM `helpdesk` AS `h`
LEFT JOIN (
SELECT `t1`.`parent` AS `parent`, `t2`.`author` AS `author`
FROM (
SELECT `parent`, MAX(`datetime`) AS `maxtime`
FROM `helpdesk`
WHERE `parent` != 0
GROUP BY `parent`
) AS `t1`
JOIN `helpdesk` AS `t2` ON `t2`.`parent` = `t1`.`parent`
AND `t2`.`datetime` = `t1`.`maxtime`
) AS `h1` ON `h1`.`parent` = `h`.`id`
WHERE `h`.`parent` = 0