I have a query that I use 2 UNIONS to get the results that I need
It may be done using a CASE statement but I could not figure it out. I will appreciated it if some can can solve this problem
This is my current query please keep in mind that viewable_by can be only 1, 2 or 3 However, client_id, team_id and created_by will be a variable depending on the user those will change
SELECT view_name, view_id, viewable_by FROM `phone_call_views`
WHERE status = 1 AND ( viewable_by = 1 AND client_id = 1)
UNION
SELECT view_name, view_id, viewable_by FROM `phone_call_views`
WHERE status = 1 AND ( viewable_by = 2 AND team_id =5 AND client_id = 1)
UNION
SELECT view_name, view_id, viewable_by FROM `phone_call_views`
WHERE status = 1 AND ( viewable_by = 3 AND created_by= 6)
This is my actual query with the variable in php
$db->getDataSet(' SELECT view_name, view_id, viewable_by FROM `phone_call_views`
WHERE status = 1 AND ( viewable_by = 1 AND client_id = '.CLIENT_ID.')
UNION
SELECT view_name, view_id, viewable_by FROM `phone_call_views`
WHERE status = 1 AND ( viewable_by = 2 AND team_id ='.TEAM_ID.' AND client_id = '.CLIENT_ID.')
UNION
SELECT view_name, view_id, viewable_by FROM `phone_call_views`
WHERE status = 1 AND ( viewable_by = 3 AND created_by= '.USER_ID.') '
);