views:

34

answers:

2

I want to join two tables (below) which i get. But then I want to do a count to see how many times each job_category is shown when contactId > 0

Any Help would be appreciated!

Tablel :

| JobPositionId | JobPositionName | JobDescriptionId | JobCategoryId | ContactId
---------------------------------------------------------------------------------
       1        |  Audio Cables   |      1           |      1        |     1
       2        |Audio Connections|      2           |      1        |     1
       3        |Audio Connections|      2           |      1        |     0
       4        |   Sound Board   |      3           |      1        |     0
       5        |   Tent Pen      |      4           |      3        |     0

Table2 :

JobCategoryId | JobCategoryName
 --------------------------------
      1       |  Audio Setup
      2       |  Stage Setup
      3       |  Tent Setup
+1  A: 

Something like

select jc.JobCategoryName, count(*) 
from JobCats jc inner join JobPostings jp on jc.JobCategoryId = jp.JobCategoryId
where jp.ContactId > 0
group by jp.JobCategoryId
Jaime
+1  A: 

Does this give you what you want:

SELECT Table2.JobCategoryId, Table2.JobCategoryName, COUNT(Table2.JobCategoryId)
FROM Table1
INNER JOIN Table2 ON Table1.JobCategoryId = Table2.JobCategoryId
WHERE Table1.ContactId > 0
GROUP BY Table2.JobCategoryId, Table2.JobCategoryName
bobs
Thanks bob, That worked, I just changed a couple things : SELECT job_category.JobCategoryId, job_category.JobCategoryName, Count(job_position.ContactId) , COUNT(job_position.JobCategoryId) FROM job_position Right Outer JOIN job_category ON job_position.JobCategoryId = job_category.JobCategoryIdGROUP BY job_category.JobCategoryId, job_category.JobCategoryName So this gives me the amount of jobpostions for all categories,I have one more question. How can I get a sum of ContactId for each JobCategoryId?
Robert de Klerk
You can add another expression to the SELECT clause. So, at the end of the SELECT line, add `, SUM(job_position.ContactId)`. This works as long as the grouping is the same as how you gather the counts.
bobs
Thanks Man, I was being an idiot - I used Count again. Thanks Alot
Robert de Klerk