Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 18th, 2006, 07:25 PM
David F
Guest
 
Posts: n/a
Default Access 2003: Left Join won't work - need help please

Hello,

I have what seems like a simple left join query,
but Access returns results like it's an inner join. I've tried
numerous combinations without success.

I have a table (ProjectList) with one row per project.
Each project has a status condition of Green, Yellow
or Red. The other table (DisplayOrder) has three rows,
one for each status condition color.

My query needs to return three rows: Green, Yellow and
Red plus the number of projects for each color condition.
One row for each color, even if no projects have
that color status.

Each time I run the query, it only returns *two* rows,
Green and Yellow, but never Red (currently, there are no
Red projects).

Why does the left join not show a red row from the
DisplayOrder table?

Thanks in advance for any and all suggestions,
David

Here's the query:

SELECT DisplayOrder.Condition,
Count(*) AS Total_Projects
FROM DisplayOrder
LEFT JOIN ProjectList
ON DisplayOrder.Condition = ProjectList.Condition
WHERE ProjectList.Status = 'Active'
AND ProjectList.Program = 'AML'
GROUP BY DisplayOrder.Condition, DisplayOrder.DisplayOrder
ORDER BY DisplayOrder.DisplayOrder

  #2  
Old December 19th, 2006, 12:25 AM
Bob Quintal
Guest
 
Posts: n/a
Default Re: Access 2003: Left Join won't work - need help please

"David F" <Save_redwoods@yahoo.comwrote in
news:1166469699.056824.289910@n67g2000cwd.googlegr oups.com:
Quote:
Hello,
>
I have what seems like a simple left join query,
but Access returns results like it's an inner join. I've
tried
Quote:
numerous combinations without success.
>
I have a table (ProjectList) with one row per project.
Each project has a status condition of Green, Yellow
or Red. The other table (DisplayOrder) has three rows,
one for each status condition color.
>
My query needs to return three rows: Green, Yellow and
Red plus the number of projects for each color condition.
One row for each color, even if no projects have
that color status.
>
Each time I run the query, it only returns *two* rows,
Green and Yellow, but never Red (currently, there are no
Red projects).
>
Why does the left join not show a red row from the
DisplayOrder table?
>
Thanks in advance for any and all suggestions,
David
>
Here's the query:
>
SELECT DisplayOrder.Condition,
Count(*) AS Total_Projects
FROM DisplayOrder
LEFT JOIN ProjectList
ON DisplayOrder.Condition = ProjectList.Condition
WHERE ProjectList.Status = 'Active'
AND ProjectList.Program = 'AML'
GROUP BY DisplayOrder.Condition, DisplayOrder.DisplayOrder
ORDER BY DisplayOrder.DisplayOrder
>
Queries apply the where clause after building the resultset from
the joins.

Solutions:
1) move the WHERE to a different query that just filters the
projectlist and left join that query with Displayorder.
2) Change the where clause so that you get null responses.
WHERE (ProjectList.Status = 'Active'
OR ProjectList.Status is Null)
AND (ProjectList.Program = 'AML'
OR ProjectList.Program is Null)

Note the use of parentheses () to get the right nesting of
conditions.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

  #3  
Old December 19th, 2006, 06:25 PM
David F
Guest
 
Posts: n/a
Default Re: Access 2003: Left Join won't work - need help please


Bob Quintal wrote:
Quote:
Queries apply the where clause after building the resultset from
the joins.
>
Solutions:
1) move the WHERE to a different query that just filters the
projectlist and left join that query with Displayorder.
2) Change the where clause so that you get null responses.
WHERE (ProjectList.Status = 'Active'
OR ProjectList.Status is Null)
AND (ProjectList.Program = 'AML'
OR ProjectList.Program is Null)
>
Note the use of parentheses () to get the right nesting of
conditions.
>
Bob,

That makes sense now; I wasn't aware about the order of the WHERE
processing taking place after the join. I used your option #1 and
query now works. Thanks!!

David

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles