I have the following query.
$query_assignments = "SELECT * FROM tb_scheduler_assignments
WHERE company_id = '".$company_id."' OR
dept_id = '".$dept_id."' OR
user_id = '".$user_id."' ORDER BY
due_date GROUP BY purchase_id";
What I'd like is a single query solution that would keep the results for user_id
over dept_id
and dept_id
over company_id
.
For example:
- if the same
purchase_id
occurs for rows that were gotten viadept_id
anduser_id
, then I only want the result for theuser_id
; - if the same
purchase_id
occurs for rows that were gotten viacompany_id
anduser_id
, then I only want the result for theuser_id