Combining three queries into one
Three different queries have been written to get the count of same columns based on different conditions.But this results in hitting the database very often and thus performance comes down.So we want to write a query which combines all the three queries into a single one.We use three different methods to invoke these queries individually.This should be avoided and made into a single call and thereby hit the database only once.Here follows,the different queries......
Query1:
SELECT COUNT(JOB_ID) JOBID
FROM EOMS_JOB_QUEUE_V
WHERE JOB_STATUS_ID != 12
AND JOB_TYPE = 18
AND AGENT_ID =4
Query2:
SELECT COUNT(JOB_ID ) JOBID FROM
EOMS_JOB WHERE JOB_STATUS_ID != 12 AND JOB_TYPE = 20 AND AGENT_ID = 4
Query3:
SELECT COUNT(JOB_ID ) JOBID FROM "+
EOMS_JOB WHERE JOB_STATUS_ID != 12 AND JOB_TYPE = 19 AND AGENT_ID = 4
Note:In the above queries the job_type alone changes and the other conditions remains the same.
[1008 byte] By [
umamahi] at [2007-11-11 10:14:20]

# 1 Re: Combining three queries into one
Umamahi,
I would suggest trying an IN statement to solve this by combing the JOB_TYPE parameters.
Dave
SELECT COUNT(JOB_ID) JOBID
FROM EOMS_JOB_QUEUE_V
WHERE JOB_STATUS_ID != 12
AND JOB_TYPE in (18,19,20)
AND AGENT_ID =4