tags:

views:

35

answers:

1

How can I combine Join these two tables?

Table 1

SELECT job_category.JobCategoryId, job_category.JobCategoryName, count(job_position.JobCategoryId) 
AS AvailableCategories
FROM job_position 
Right Outer JOIN job_category ON job_position.JobCategoryId = job_category.JobCategoryId
GROUP BY job_category.JobCategoryId, job_category.JobCategoryName

Table 2

(SELECT job_category.JobCategoryId, job_category.JobCategoryName, count(job_position.ContactId) AS AllocatedJobs
FROM job_position 
Right Outer JOIN job_category ON job_position.JobCategoryId = job_category.JobCategoryId
WHERE job_position.ContactId > 0
GROUP BY job_category.JobCategoryId, job_category.JobCategoryName)

Thanks

A: 

I think it should be like this

Select T1.JobCategoryId, T1.JobCategoryName, T1.AvailableCategories, T2.AllocatedJobs    
FROM    
 (SELECT job_category.JobCategoryId as JobCategoryId, job_category.JobCategoryName as JobCategoryName, count(job_position.JobCategoryId) 
AS AvailableCategories
FROM job_position 
Right Outer JOIN job_category ON job_position.JobCategoryId = job_category.JobCategoryId
GROUP BY job_category.JobCategoryId, job_category.JobCategoryName) as T1 

INNER JOIN 

((SELECT job_category.JobCategoryId as  T2JobCategoryId, job_category.JobCategoryName as T2JobCategoryName, count(job_position.ContactId) AS AllocatedJobs
FROM job_position 
Right Outer JOIN job_category ON job_position.JobCategoryId = job_category.JobCategoryId
WHERE job_position.ContactId > 0
GROUP BY job_category.JobCategoryId, job_category.JobCategoryName)) as T2
ON T1.JobCategoryId = T2.T2JobCategoryId
Azhar
Thanks Man, I never understood till seeing how you did that - Appreciate it!!!!
Robert de Klerk