SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Count list from two tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

leearenaa
Starting Member

Malaysia
3 Posts

Posted - 06/20/2013 :  00:32:42  Show Profile  Reply with Quote
Hi there,
How can I query two tables to get the list and number of total count? Below is my tables:
User's Table:
UserID | ProfessionID
1234 | 1
3241 | 2
3435 | 1

Profession's table
ProfessionID | ProfessionName
1 | Student
2 | Chef
3 | Others

So how can I query that the output will be coming as below?
ProfessionName | TotalCount
Student | 2
Chef | 1
Others | 0

Thank you for the advance.

LeeAreNaa

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/20/2013 :  00:50:14  Show Profile  Reply with Quote

SELECT p.ProfessionName,
COUNT(UserID) AS TotalCount
FROM Profession p
LEFT JOIN User u
ON p.ProfessionID = u.ProfessionID
GROUP BY p.ProfessionName


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

leearenaa
Starting Member

Malaysia
3 Posts

Posted - 06/20/2013 :  01:55:37  Show Profile  Reply with Quote
Its look great...
Thank you..

quote:
Originally posted by visakh16


SELECT p.ProfessionName,
COUNT(UserID) AS TotalCount
FROM Profession p
LEFT JOIN User u
ON p.ProfessionID = u.ProfessionID
GROUP BY p.ProfessionName


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




LeeAreNaa
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/20/2013 :  02:00:56  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000