SELECT
`a`.`ID_` AS `TASK_ID`,
`a`.`PROC_INST_ID_` AS `PROC_INST_ID`,
`a`.`PROC_DEF_ID_` AS `PROC_DEF_ID_`,
`a`.`TASK_DEF_KEY_` AS `ACT_ID`,
`a`.`NAME_` AS `ACT_NAME`,
`a`.`ASSIGNEE_` AS `ASSIGNEE`,
`a`.`DELEGATION_` AS `DELEGATION_ID`,
`a`.`DESCRIPTION_` AS `DESCRIPTION`,
`a`.`CREATE_TIME_` AS `CREATE_TIME`,
`a`.`DUE_DATE_` AS `DUE_DATE`,
`i`.`USER_ID` AS `CANDIDATE`,
`f`.`KEY_` AS `KEY_`
FROM
((
`act_ru_task` `a`
LEFT JOIN (
SELECT DISTINCT
`u`.`TASK_ID_` AS `TASK_ID_`,
`u`.`USER_ID` AS `USER_ID`
FROM
(
SELECT
`i`.`TASK_ID_` AS `TASK_ID_`,
`i`.`USER_ID_` AS `USER_ID`
FROM
( `act_ru_identitylink` `i` JOIN `act_ru_task` `t` )
WHERE
((
`i`.`TASK_ID_` IS NOT NULL
)
AND ( `i`.`USER_ID_` IS NOT NULL )
AND ( `i`.`TASK_ID_` = `t`.`ID_` )
AND isnull( `t`.`ASSIGNEE_` )
AND ( `i`.`TYPE_` = 'candidate' )) UNION
SELECT
`i`.`TASK_ID_` AS `TASK_ID_`,
`r`.`USER_ID_` AS `USER_ID`
FROM
(( `act_ru_identitylink` `i` JOIN `act_id_membership` `r` ) JOIN `act_ru_task` `t` )
WHERE
((
`i`.`TASK_ID_` IS NOT NULL
)
AND ( `i`.`GROUP_ID_` IS NOT NULL )
AND ( `i`.`TASK_ID_` = `t`.`ID_` )
AND isnull( `t`.`ASSIGNEE_` )
AND ( `i`.`TYPE_` = 'candidate' )
AND ( `i`.`GROUP_ID_` = `r`.`GROUP_ID_` ))) `u`
) `i` ON ((
`a`.`ID_` = `i`.`TASK_ID_`
)))
LEFT JOIN `act_re_procdef` `f` ON ((
`a`.`PROC_DEF_ID_` = `f`.`ID_`
)))