473,387 Members | 1,578 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,387 software developers and data experts.

How do you show records with no matching values?

147 100+
I am not sure if I worded my question correctly. But what I want to do is run a report from two related tables as follows:

The first table is called Category - it has one field, called Category, that is also the primary key. There are 18 categries listed in the table.

The second table is called CaseManagement, with no primary key, and multiple fields including Category which is taken from the related Category table.

They are related with a one to many link from Category to CaseManagement.

In my report I want to list all the categories from the Category table followed by the number of cases in each category from the CaseManagement table.

My problem is that if a categoy does not have any related data in the CaseManagement table, the category is not listed in my report. I want the report to include every category from the Cattegory table and show a 0 for it if it does not have any related data in the CaseManagement table.

Thanks for any help
Dan
Nov 22 '07 #1
16 1918
SELECT Category.Category, Count(CaseManagement.Category) AS CountOfCategory
FROM Category LEFT JOIN CaseManagement ON Category.Category = CaseManagement.Category
GROUP BY Category.Category;
Nov 22 '07 #2
DAHMB
147 100+
SELECT Category.Category, Count(CaseManagement.Category) AS CountOfCategory
FROM Category LEFT JOIN CaseManagement ON Category.Category = CaseManagement.Category
GROUP BY Category.Category;

Thankyou for your response but where do I place this code? Please excuse my ignorance.

Thank you for your help.
Dan
Nov 22 '07 #3
From the Database Window, select the Queries tab.

Click New, and at the New Query dialog box select Design View and then click OK.

At the Show Table dialog box, click Close.

From the Access menu bar, click View ~ SQL View and paste the code into that window.

From the Access menu bar, click View ~ Design View and you'll see the query in the graphical design window. Save the query.

When you run the query you'll see the results.
Nov 22 '07 #4
DAHMB
147 100+
From the Database Window, select the Queries tab.

Click New, and at the New Query dialog box select Design View and then click OK.

At the Show Table dialog box, click Close.

From the Access menu bar, click View ~ SQL View and paste the code into that window.

From the Access menu bar, click View ~ Design View and you'll see the query in the graphical design window. Save the query.

When you run the query you'll see the results.

Thank you very much for you reply but I am geting a Syntexc error in Join Operation. I have typed the code as follows the table names are different because I was trying to be as clear as possible on my original post but these are the actual names:

SELECT tblOffenses.Offenses, Count(tblCaseManagement.Offense) AS CountOfOffense FROM Offense LEFT JOIN tblCaseManagement ON tblOffenses.Offenses = tblCaseManagement.Offense GROUP BY tblOffenses.Offenses;

Thank you again for your time and help.
Dan
Nov 23 '07 #5
You have a typo - you wrote

SELECT tblOffenses.Offenses, Count(tblCaseManagement.Offense) AS CountOfOffense FROM Offense LEFT JOIN tblCaseManagement ON tblOffenses.Offenses = tblCaseManagement.Offense GROUP BY tblOffenses.Offenses;

but it should be

SELECT tblOffenses.Offenses, Count(tblCaseManagement.Offense) AS CountOfOffense FROM tblOffenses LEFT JOIN tblCaseManagement ON tblOffenses.Offenses = tblCaseManagement.Offense GROUP BY tblOffenses.Offenses;
Nov 23 '07 #6
DAHMB
147 100+
You have a typo - you wrote

SELECT tblOffenses.Offenses, Count(tblCaseManagement.Offense) AS CountOfOffense FROM Offense LEFT JOIN tblCaseManagement ON tblOffenses.Offenses = tblCaseManagement.Offense GROUP BY tblOffenses.Offenses;

but it should be

SELECT tblOffenses.Offenses, Count(tblCaseManagement.Offense) AS CountOfOffense FROM tblOffenses LEFT JOIN tblCaseManagement ON tblOffenses.Offenses = tblCaseManagement.Offense GROUP BY tblOffenses.Offenses;

Thank you so very much!!! I have been racking my brains for a week on this! I reealy appreciate it. I will try it tommorrow when I go to work and let you know how I made out. Thank you for your help please check back for me in case I have any more issues.
Dan
Nov 23 '07 #7
DAHMB
147 100+
OK Great now I understand how to do this. But now I have a form where I list twwo dates to limit a search between. Now if I add the search line it gives me a resuly with just the fields with data again. I need the fields from tblOffense to show with 0 in the limited search as well. my sql with the date search looks like this:

SELECT tblOffenses.Offenses, Count(tblCaseManagement.Offense) AS CountOfOffense
FROM tblOffenses LEFT JOIN tblCaseManagement ON tblOffenses.Offenses = tblCaseManagement.Offense
GROUP BY tblOffenses.Offenses
Having (((Count(tblCaseManagement.Offense)) Between [Forms]![frmIntakeSearch]![Date1] And [Forms]![frmIntakeSearch]![Date2]));


What am I doing wrong?
Thanks again
Dan
Nov 25 '07 #8
DAHMB
147 100+
Sorry I posted the wrong sql it looks like this:

SELECT tblOffenses.Offenses, Count(tblCaseManagement.Offense) AS CountOfOffense
FROM tblOffenses LEFT JOIN tblCaseManagement ON tblOffenses.Offenses = tblCaseManagement.Offense
WHERE (((tblCaseManagement.DateOpened) Between [Forms]![frmIntakeSearch]![Date1] And [Forms]![frmIntakeSearch]![Date2]))
GROUP BY tblOffenses.Offenses;
Nov 25 '07 #9
Dan,

I don't fully understand the logical relationship between your two tables, but when you apply criteria to the tblCaseManagement table, the effect is that you're making it act like an INNER JOIN, because you are requiring a matching record in tblCaseManagement.

In any event, can you try this & see if it gives you the desired results:

SELECT tblOffenses.Offenses, Count(tblCaseManagement.Offense) AS CountOfOffense
FROM tblOffenses LEFT JOIN tblCaseManagement ON tblOffenses.Offenses = tblCaseManagement.Offense
WHERE (((tblCaseManagement.DateOpened) Between [Forms]![frmIntakeSearch]![Date1] And [Forms]![frmIntakeSearch]![Date2]))
OR (tblCaseManagement.DateOpened) IS NULL
GROUP BY tblOffenses.Offenses;
Nov 26 '07 #10
DAHMB
147 100+
Thank you it did not work correctly it did not show every record and there was no method to the ones it did not show. What I did was create two queries as below:
the first:

SELECT tblOffenses.Offenses, tblCaseManagement.DateOpened
FROM tblOffenses LEFT JOIN tblCaseManagement ON tblOffenses.Offenses = tblCaseManagement.Offense
WHERE (((tblCaseManagement.DateOpened) Between [Forms]![frmIntakeSearch]![Date1] And [Forms]![frmIntakeSearch]![Date2]));

the second:

SELECT tblOffenses.Offenses, Count(qryMonthlyIntakeSUB.Offenses) AS CountOfOffenses
FROM tblOffenses LEFT JOIN qryMonthlyIntakeSUB ON tblOffenses.Offenses = qryMonthlyIntakeSUB.Offenses
GROUP BY tblOffenses.Offenses;

Do you thionk I could do just one query with the above in a Union query? and would I need anything to be different if I did?

Dan
Nov 26 '07 #11
Dan, is this what you want in the results:

Do you always want to see every record from tblOffenses.Offenses, along with a count of tblCaseManagement.Offense records that fall within the date range?

If that is the case, you would use two queries. The first query would filter for the records that fall inside your date range. Let's call it qryCaseFilter:

SELECT tblCaseManagement.Offense
FROM tblCaseManagement
WHERE (((tblCaseManagement.DateOpened) Between [Forms]![frmIntakeSearch]![Date1] And [Forms]![frmIntakeSearch]![Date2]));

The second query would be similar to my original solution, except that we use qryCaseFilter instead of the full table, something like this:

SELECT tblOffenses.Offenses, Count(qryCaseFilter.Offense) AS CountOfOffense FROM tblOffenses LEFT JOIN qryCaseFilter ON tblOffenses.Offenses = qryCaseFilter.Offense
GROUP BY tblOffenses.Offenses;
Nov 26 '07 #12
DAHMB
147 100+
Yes thank you that is exactly what I was looking for. Thankyou.

Since I am here I have another question on reports. I will ask it here post it normally because I am not sure if that is a required protocal on this site..

I have a report based on a query, in the report I have three columns

Column1
=Sum(Abs([qryMonthlyReport]![ClearanceCode] Like "*"))

Column2
=Sum(Abs([qryMonthlyReport]![ClearanceCode]="O"))

Column3
=Sum(Abs([qryMonthlyReport]![ClearanceCode]<>"O"))

My problem is I also want to limit the columns based on a date range in a form such as:
Between [Forms]![frmMonthlyReport]![Date1] And [Forms]![frmMonthlyReport]![Date2]

I just can't figure out the correct way I keep getting errors.
Thanks
Dan
Nov 27 '07 #13
Hi Dan, glad I could help.

As far as your new question, I'm also fairly new to this forum, but I think if you start a new thread you'll get more views - others will see the highlighted "new post" tag and be more likely to read & respond. There's usually more than one way to solve a given problem in Access, maybe somebody else might have a better idea.

Back to your new question, the general approach could be like this:

Column2
=Sum(IIf(([qryMonthlyReport]![ClearanceCode]="O") And (TheDate Between [Forms]![frmMonthlyReport]![Date1] And [Forms]![frmMonthlyReport]![Date2],1,0)))
Nov 27 '07 #14
DAHMB
147 100+
Hi Dan, glad I could help.

As far as your new question, I'm also fairly new to this forum, but I think if you start a new thread you'll get more views - others will see the highlighted "new post" tag and be more likely to read & respond. There's usually more than one way to solve a given problem in Access, maybe somebody else might have a better idea.

Back to your new question, the general approach could be like this:

Column2
=Sum(IIf(([qryMonthlyReport]![ClearanceCode]="O") And (TheDate Between [Forms]![frmMonthlyReport]![Date1] And [Forms]![frmMonthlyReport]![Date2],1,0)))

It won't work, it won't even let me exit out of the expression box. Any ideas?
Dan
Nov 27 '07 #15
I misplaced a parenthesis in the IIf statement:

Column2
=Sum(IIf(([qryMonthlyReport]![ClearanceCode]="O") And (TheDate Between [Forms]![frmMonthlyReport]![Date1] And [Forms]![frmMonthlyReport]![Date2],1,0)))

should be

Column2
=Sum(IIf(([qryMonthlyReport]![ClearanceCode]="O") And (TheDate Between [Forms]![frmMonthlyReport]![Date1] And [Forms]![frmMonthlyReport]![Date2]),1,0))
Nov 27 '07 #16
DAHMB
147 100+
I misplaced a parenthesis in the IIf statement:

Column2
=Sum(IIf(([qryMonthlyReport]![ClearanceCode]="O") And (TheDate Between [Forms]![frmMonthlyReport]![Date1] And [Forms]![frmMonthlyReport]![Date2],1,0)))

should be

Column2
=Sum(IIf(([qryMonthlyReport]![ClearanceCode]="O") And (TheDate Between [Forms]![frmMonthlyReport]![Date1] And [Forms]![frmMonthlyReport]![Date2]),1,0))

That was it Thankyou!!!!!!!
Dan
Nov 29 '07 #17

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

Similar topics

2
by: rowan[canspam] | last post by:
I have two tables ITEMS: items,description,mfg MANUFACTURER: mfg,full_name The items database has 230,000 records, the manufacturer, 493 records. I want to see how many records in the...
7
by: Philip Mette | last post by:
I have been searching many postings and I cant seem to find anyone that has this answer so I decided to post. I am using SQL (Transact-SQL).If I have 2 tables with columns...
4
by: news.online.no | last post by:
In a query, I need too be able to show if a parent record has a child record. Using the query in a combo box too select record in a form. Thanks :)
1
by: snOOp | last post by:
I am trying to combine the data from two similar tables into one query, but I need for all of the records from both tables to show up and I want the ones that have matching 'emplid' to be combined...
2
by: Lauren Quantrell | last post by:
I am using a stored procedure as the recordsource on an MS-Access2000 form: Forms!frmName.RecordSource = "dbo.myStoredProcedure" The stored procedure creates a temp table #Contacts and then...
6
by: Sven Pran | last post by:
Probably the answer is there just in front of me only awaiting me to discover it, but: 1: I want to build a query that returns all records in one table for which there is no successful "join"...
2
by: Zeljko | last post by:
I'm creating Address book. Header of the main form (frmAddress) contains combo box (cboFilter) to filter records by Occupation on main Form(Ocupation1). That's working. Combo box also have "Show...
4
by: J | last post by:
I am editing a pre-existing view. This view is already bringing data from 40+ tables so I am to modify it without screwing with anything else that is already in there. I need to (left) join it...
1
by: Kev | last post by:
Hello I have a form (RosterForm) based on a table - RosterRange RosterRange has 4 fields: RosterRangeID Autonumber RosterStartDate Date RosterEndDate Date (probably...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.