I have 2 queries that gives me 2 different output even though performs same operation.
Query1 :
SELECT fa.maintenance_request_id, count(fa.id) AS row_count FROM file_associations fa JOIN files f on (f.id = fa.file_id and f.cid = fa.cid) WHERE fa.cid = 12345 AND fa.maintenance_request_id IN (17312470) AND fa.deleted_by IS NULL AND fa.deleted_on IS NULL GROUP BY fa.maintenance_request_id
Result: No result found
Query 2 :
SELECT COUNT(1) AS row_count FROM file_associations fa JOIN files f ON (f.id = fa.file_id and f.cid = fa.cid) WHERE fa.cid = 12345 AND fa.maintenance_request_id = 17312470 AND fa.deleted_by IS NULL AND fa.deleted_on IS NULL
Result : row_count = 0
Is there any way to get row_count as 0 using 1st query? As in first query there is possibility that we get multiple maintenance_request_ids with 0 count.
I tried by removing group by clause in 1st query then but then it failed for desired result.
Expected result as : from 1st query if we have row_count as 0 then it should be returned as 0 rather than no result found.