MySQL Forums
Forum List  »  Newbie

MYSQL COUNT RETURNING INACCURATE DATA
Posted by: Mofoluwasho Kolawole Jimoh
Date: October 17, 2021 02:29PM

Good day all. I am working on retrieving data from the database across some tables.

My query is shown below.

SELECT DISTINCT applicable_areas.area, applicable_areas.id as id, count(distinct supreme_applicable_areas.applicable_area_id) as supreme_court_cases, count(distinct appeal_applicable_areas.applicable_area_id) as appeal_court_cases
FROM `applicable_areas`
JOIN appeal_applicable_areas ON appeal_applicable_areas.applicable_area_id = applicable_areas.id
JOIN supreme_applicable_areas ON supreme_applicable_areas.applicable_area_id = applicable_areas.id
JOIN cp_cases_counsel ON ( (cp_cases_counsel.suitno = supreme_applicable_areas.suitno) OR (cp_cases_counsel.suitno = appeal_applicable_areas.suitno))
WHERE cp_cases_counsel.counsel_id = 54
GROUP BY applicable_areas.area, applicable_areas.id
ORDER BY applicable_areas.area ASC;

It seems as if it checks for the occurrence of values from the 'supreme_applicable_areas' table and if found, go ahead to check for that on the 'appeal_applicable_areas' table. So, if a there is no value for supreme, but there is for appeal, it brings results for both supreme and appeal. However I want it to pick one or the other.

Is there a way of achieving this?

Thanks in advance

Options: ReplyQuote


Subject
Written By
Posted
MYSQL COUNT RETURNING INACCURATE DATA
October 17, 2021 02:29PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.