473,382 Members | 1,409 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.

How to count records in Many to Many scenario?

91
Hi,

I have two tables, [Rules] and [Process] which are in a many to many relationship via a junction table[JRule_Process]. It has the following field (relevant ones for this discussion):

[Rules]
RuleID
RuleName

[Process]
ProcessID
DetailProcessName

[JRule_Process]
JunctionID
RuleID
ProcessID


I have almost 5000 unique rules and around 100 Detail Process Names. Currently, only some of the rules are mapped with processes.
I have designed a query (with JOIN) which shows all rules and processes where it is mapped and where it is not. So, when I run the query, I can see all the [RuleName] and partially populated column for the [DetailProcessName].

I want to do a count of the "blank" record in the [DetailProcessName] column. How can I do it?

For the above scenerio, what I want is to count the number of process records where it is mapped to Rule and where it is not.

In the query design view, I only selected [DetailProcessName] and I put the critiria as "Process.DetailProcessName = Null" and used the Count function but it is not working.

How do I design the query so that I can count all records where [ProcessName] is mapped to a [RuleName] and also where it is not ?

Please advise.

Thanks,
SG
Apr 26 '12 #1
5 1518
sg2808
91
Hi,

In the design query, I have selected a field and I have marked "Unique Value" as Yes in the property. When I run the query I see 345 records. However, with the same settings, when I use Total function and set the Groupby as "Count", it then shows the count value as 688. Why is this so? It seems that the count funtion is not taking into account the "Unique Value" setting.

Wondering if there are any additional settings which will give the count value as 345?

Any suggestions pls?

Thanks,
SG
Apr 26 '12 #2
Rabbit
12,516 Expert Mod 8TB
You'll have to use two queries. One query will do a count on Processes where the ID EXISTS in the junction table. The other one will do the same thing except where the ID NOT EXISTS.
Apr 26 '12 #3
Rabbit
12,516 Expert Mod 8TB
Can't help without seeing the code and sample data.

But just so you're aware, using DISTINCT only affects the final values displayed. It's not used to control what is input into the query engine. To do that, subquery the DISTINCT and then do the count in the outer query.

Is this related to your thread about counting MANY to MANY records?
Apr 26 '12 #4
sg2808
91
Thanks Rabbit.

Sorry, I am not good with SQL and I trying to use the Query Design view in Access to query the data. Not sure how to do this in the design view.

Yes, it is related to my previous thread.
Apr 27 '12 #5
Rabbit
12,516 Expert Mod 8TB
Please do not double post your questions. I have merged the thread with the original.

If you're going to be doing work in databases, I strongly suggest you learn SQL.

However, you can replicate the functionality by creating one query that selects your distinct records. And then another query that uses that query to do your counts.
Apr 27 '12 #6

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

Similar topics

1
by: ning | last post by:
It's easy to present "One - Many" relationship in XML, but how to present "Many - Many" relationship in XML?
3
by: deko | last post by:
I have a form with a subform datasheet - I need code behind the OnDelete event of the subform: Private Sub Form_Delete(Cancel As Integer) 'do something that depends on which record is deleted...
2
by: PeteCresswell | last post by:
This is pursuant to another thread I tried to start, but can't find on my server. I've got to store rolling rates of return for investment funds - calendar year, quarterly, and monthly To cut...
1
by: Ronald S. Cook | last post by:
I have the following code for which I would like to know how many records are returned. G2BTel.Classes.MSO objMSO; objMSO = new G2BTel.Classes.MSO grdMSO.DataSource = objMSO.SelectMSO(); It...
4
by: gualtmacchi | last post by:
I'm processing an XML input file getting a plain text file where from M nodes I got N output lines... It's not relevant but the input file is a recordset coming from a database and the output is...
4
by: Sjef ten Koppel | last post by:
Hi, I've a small problem. I have a table in which one column is date. I want to count the records for statiscs in a temptable grouped by months lets say 12 months back. e.g. month 1 counts 164...
1
by: dfw1417 | last post by:
I have used a query and report filter to return records related to a specific account id. I want to print a report including only the latest 6 records out of the set returned by the record filter. I...
5
by: Soccer5 | last post by:
Trying to Count records on a report that meet a certain criteria. Have a text box in the Report Footer that has the following in the Control Source: =Count(="S") This does not work. It...
6
markrawlingson
by: markrawlingson | last post by:
Hopefully someone can help me out with this, it's driving me nuts... I have two tables - We'll call them table1 and table2. Table1 holds event information, and table2 holds user registration data...
5
by: phill86 | last post by:
Hi I want to be able to count records in a dao.querydef recordset but I keep getting the error message method or data member not found I have also tried to find out if the recordset is at...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.