473,382 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Counting with an Inner Join.

I have two tables.

TBL_PRACTICE
Practice_ID (primary key)
Practice_Name
etc.

TBL_BRANCH
Branch_ID (primary key)
Branch_Name
Practice_ID
etc.

I need to create a view that has 2 fields. Practice Name, Number of Branches.

I have the following SQL, but this counts all the branches, not just the branches for this particular practice.

Expand|Select|Wrap|Line Numbers
  1. SELECT     TBL_PRACTICE.Practice_ID, TBL_PRACTICE.Practice_Name,
  2.     (SELECT count(TBL_BRANCH.Branch_ID) FROM TBL_BRANCH) AS Branches
  3. FROM TBL_PRACTICE INNER JOIN
  4.     TBL_BRANCH ON TBL_PRACTICE.Practice_ID = TBL_BRANCH.Practice_ID
If someone could let me know how I count only the branches for the corresponding Practice.

Thanks in advance, much appriciated.
Oct 18 '09 #1
1 2273
mwasif
802 Expert 512MB
Use COUNT() and GROUP BY
Expand|Select|Wrap|Line Numbers
  1. SELECT TBL_PRACTICE.Practice_ID, TBL_PRACTICE.Practice_Name, COUNT(TBL_BRANCH.Branch_ID) AS Branches
  2. FROM TBL_PRACTICE INNER JOIN
  3. TBL_BRANCH ON TBL_PRACTICE.Practice_ID = TBL_BRANCH.Practice_ID
  4. GROUP BY Practice_Name
Oct 18 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Travers Naran | last post by:
Here's the basic idea. I have a dictionary of substrings (the substrings stored as keys). I have a list of strings. I want to find out, for each word in the dictionary, how many times the...
3
by: Ike | last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL 4.0.20-standard. Thus, in trying to expedite the query, I am trying to set indexes in my tables. My query requires four...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
4
by: Chad Reid | last post by:
Hello, I have a bit of code that obviously doesn't work, but I need help creating a query that would have the same effect as if this query was working. SELECT * FROM (SELECT Count(*) AS...
5
by: chrisc | last post by:
Hello, Hope this is the right place for this... I am creating a testing database for components as they come off a production line. My reports need to select faults that are found, as well...
18
by: ChadDiesel | last post by:
I appreciate the help on this group. I know I've posted a lot here the last couple of weeks, but I was thrown into a database project at my work with very little Access experience. No other...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
0
by: josur | last post by:
Hello, Im a new user of SSAS and at the moment im trying to browse a cube to output the total of contacts within a criteria. I have one measure(fact table) named Contacts Count and 4...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.