473,465 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trouble With Left Join

I created this query in Access with the Design View.

SELECT Fiscal_Period.FiscalKey, Invoice.type, Invoice.accid,
Sum(Invoice.Total) AS Amount
FROM Fiscal_Period LEFT JOIN Invoice ON Fiscal_Period.FiscalKey =
Invoice.FiscalKey
WHERE (((Invoice.accid)=29))
GROUP BY Fiscal_Period.FiscalKey, Invoice.type, Invoice.accid
HAVING (((Invoice.type)=0))
ORDER BY Invoice.accid, Fiscal_Period.FiscalKey, Invoice.type;

I have 37 fiscal periods in the table from 200301 until 200601. I am
expecting to get 37 records, one for each record, but I am only
getting records for the ones in the Invoice table.

How do I get a record for the months in which there are no records in
the Invoice table.

In the query builder, I clicked on the join option thay says "Include
ALL records from Fiscal_Period and only those records from Invoice
where the joined fields are equal.

Thnks.
Dec 19 '05 #1
2 1283
On Mon, 19 Dec 2005 22:36:04 GMT, New Guy <ne****@yahoo.com> wrote:
I created this query in Access with the Design View.

SELECT Fiscal_Period.FiscalKey, Invoice.type, Invoice.accid,
Sum(Invoice.Total) AS Amount
FROM Fiscal_Period LEFT JOIN Invoice ON Fiscal_Period.FiscalKey =
Invoice.FiscalKey
WHERE (((Invoice.accid)=29))
GROUP BY Fiscal_Period.FiscalKey, Invoice.type, Invoice.accid
HAVING (((Invoice.type)=0))
ORDER BY Invoice.accid, Fiscal_Period.FiscalKey, Invoice.type;

I have 37 fiscal periods in the table from 200301 until 200601. I am
expecting to get 37 records, one for each record, but I am only
getting records for the ones in the Invoice table.

How do I get a record for the months in which there are no records in
the Invoice table.

In the query builder, I clicked on the join option thay says "Include
ALL records from Fiscal_Period and only those records from Invoice
where the joined fields are equal.
I *think* that your Having clause is restricting the resultset to
those rows where Invoice.Type =0. With that said, if you have a row
that is built from a Fiscal_Period that has no matching Invoice, that
row will first be included (in the Left Join) and then, since it
doesn't "have" an Invoice, no longer be included.

I think the same thing goes for the Where clause.

So I think you will need to "OR" both of those with something that
will keep your Fiscal_Period rows where there are no Invoices.

Something like:
WHERE (((Invoice.accid)=29) OR ISNULL(Invoice.accid))
and
HAVING (((Invoice.type)=0) OR ISNULL(Invoice.accid))


I'm not sure the ISNULL will work in both clauses (I know it will work
in the WHERE clause).

Try it and see what happens.

mike

Dec 19 '05 #2
On Mon, 19 Dec 2005 23:34:25 GMT, mb******@pacbell.net.invalid (Mike
Preston) wrote:
On Mon, 19 Dec 2005 22:36:04 GMT, New Guy <ne****@yahoo.com> wrote:
I *think* that your Having clause is restricting the resultset to
those rows where Invoice.Type =0. With that said, if you have a row
that is built from a Fiscal_Period that has no matching Invoice, that
row will first be included (in the Left Join) and then, since it
doesn't "have" an Invoice, no longer be included.

I think the same thing goes for the Where clause.

Yes, that did it.

Thanks a lot.
Dec 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Adam i Agnieszka Gasiorowski FNORD | last post by:
I need help width formulating the most effective (in terms of processing time) SQL query to count all the "new" documents in the repository, where "new" is defined as "from 00:00:01 up to...
5
by: Geremy | last post by:
Hi Consider two tables id1 code1 ----------- ----- 1 a 2 b 3 c id2 code2 value
4
by: jbm05 | last post by:
Hi, I'm curious about the computational complexity of a query I have. The query contains multiple nested self left joins, starting with a simple select, then doing a self left join with the...
2
by: bob | last post by:
Could someone help me get the following SQL statement working? SELECT standardgame.gamename, standardgame.rowteamname, standardgame.colteamname, standardgame.dollarvalue, standardgame.gameid,...
1
by: Giordano | last post by:
I am trying to construct a report menu that will allow the user to select any combination of 3 variables from 3 combo boxes (Select Subject/SelectCategory/Date Range). There are 2 possible options...
9
by: chadlupkes | last post by:
I'm getting NULLs where there shouldn't be. Any help is appreciated. Here are the tables: precinct Field Type Null Key Default Extra id smallint(6) PRI...
6
by: cberthu | last post by:
Hi all, I have a strange (at least for me) things happening. I am save the result of an outer join into a file and I read this file and put these values into a table. The first row written...
2
by: execworks | last post by:
I would appreciate help with the following Function. The SQL statement below returns a Recordcount = 0, yet, when it runs in the query designer it returns the correct count of 40 Private...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
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...
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...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.