1
SELECT task_name,task_id,
       SUBSTR(task_text,1,20) AS task_text,
       task_project_id,task_status
    FROM projectboard_tasks
    WHERE task_status IN  ('0','3')
     AND  task_assigner = 31 OR  task_assigned_to = 31

Here in query i return the rows with task status 0 and 3 but due to OR the query returns rows which are not matching the task_status condition

I get the rows which are not with status 0 or 3 because it match the task_assigner with other rows and shows the result.

Is there any workaround for this ?

2

You need to apply proper parenthesis ( ). You need to apply parenthesis for the condition (task_assigner = 31 OR task_assigned_to = 31), so the task_status IN ('0', '3') and the task_assigner both conditions will satisfy.

The working query will be:

SELECT task_name, task_id, SUBSTR(task_text, 1, 20) AS task_text,
       task_project_id, task_status
FROM projectboard_tasks
WHERE task_status IN ('0', '3')
    AND (task_assigner = 31 OR task_assigned_to = 31)
  • @ADP You are welcome. Happy to help. – Arulkumar Sep 28 '16 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.