• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • Last Modified:

SQL search / results from 2 tables

Using SQL Server 2008 Management Studio

Table 1: MasterAccounts
PK   MasterAccount_ID     int
LeadSourceProvider_ID    int

Table 2: LeadSourceProviders
PK    LeadSourceProvider_ID     int
LeadSourceProviderName       nvarchar(50)

the result I am looking for is as follows (when executing the sql script) :

LeadSourceProviderName,  [count of Master Accounts using that LeadSourceProviderName)
LeadSourceProviders has a 1-to-Many relationship with MasterAccounts table.

How would you construct a SQL query to do this please?
0
amillyard
Asked:
amillyard
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
SELECT a.LeadSourceProviderName, (SELECT COUNT(*) FROM MasterAccounts m WHERE m.LeadSourceProvider_ID = a.LeadSourceProvider_ID ) as cnt
from LeadSourceProviders a
0
 
amillyardAuthor Commented:
spot on -- thank you aneeshattingal  :-)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now