mysql - SQL doesn't do what I need -
i have problem second join in query. users have ability change order of tasks not affect ordering of other users. when no order yet set user tasks not displayed him because second join not return results despite being left outer join
select `workflow_tasks`.*, `workflow_task_order`.`order`, `workflow_group_tasks`.`group_id` `pivot_group_id`, `workflow_group_tasks`.`task_id` `pivot_task_id` `workflow_tasks` inner join `workflow_group_tasks` on `workflow_tasks`.`id` = `workflow_group_tasks`.`task_id` left outer join `workflow_task_order` on `workflow_tasks`.`id` = `workflow_task_order`.`task_id` (`workflow_task_order`.`user_id` = 1 or `workflow_task_order`.`user_id` null) , `workflow_group_tasks`.`group_id` in (1, 2, 3, 7) group `workflow_tasks`.`id` order `order` asc
i suppose should apply user filter in different table workflow_task_order
, when want fetch tasks of particular user. if that's user @ point (what suppose true), query not return results. it's because said don't have "order" records user yet, , don't have neither entries there user null
id obviously.
i suppose have user_id
column in workflow_tasks
too, following query should work fine , result expect:
select `workflow_tasks`.*, `workflow_task_order`.`order`, `workflow_group_tasks`.`group_id` `pivot_group_id`, `workflow_group_tasks`.`task_id` `pivot_task_id` `workflow_tasks` inner join `workflow_group_tasks` on `workflow_tasks`.`id` = `workflow_group_tasks`.`task_id` left outer join `workflow_task_order` on `workflow_tasks`.`id` = `workflow_task_order`.`task_id` `workflow_tasks`.`user_id` = 1 , `workflow_group_tasks`.`group_id` in (1, 2, 3, 7) group `workflow_tasks`.`id` order `order` asc
however if have tasks common different users (e.g. team) , don't have user_id
in other table workflow_task_order
, following query should more suitable:
select `workflow_tasks`.*, `workflow_task_order`.`order`, `workflow_group_tasks`.`group_id` `pivot_group_id`, `workflow_group_tasks`.`task_id` `pivot_task_id` `workflow_tasks` inner join `workflow_group_tasks` on `workflow_tasks`.`id` = `workflow_group_tasks`.`task_id` left outer join `workflow_task_order` on (`workflow_tasks`.`id` = `workflow_task_order`.`task_id` , `workflow_task_order`.`user_id` = 1) `workflow_group_tasks`.`group_id` in (1, 2, 3, 7) group `workflow_tasks`.`id` order `order` asc
Comments
Post a Comment