I must be overlooking something simple because I've done this type of query before and it usually works. I'm trying to display all locations regardless of data so that I can identify which items we still need to add to the detail table. For some reason, when I do a left join, it is not showing the missing items. Here is an example:
Note there are more records per location in this table, for space considerations only showing one record per location. Also, these aren't the real table names.
[tt]
TABLE Details
--------------
RunDate WeekNo Location
2/13/2006 21 SF
2/13/2006 21 LA
2/13/2006 21 SD
TABLE Location
--------------
Location (Primary Key)
SF
LA
SD
SJ
SR
--Actual Result--
Location.Location Details.Location
SF SF
LA LA
SD SD
--Needed Result--
Location.Location Details.Location
SF SF
LA LA
SD SD
SJ [red][null][/red]
SR [red][null][/red]
------------------------------------
[/tt]
Here is the query
QUERY Summary
--------------
[tt]SELECT Location.Location, Details.Location
FROM Location LEFT JOIN Details ON Location.Location = Details.Location
WHERE Details.WeekNo=21
GROUP BY Location.Location, Details.Location;[/tt]
When the query is working, I plan to display WeekNo and Sum of Location rather than having a where clause.
Note there are more records per location in this table, for space considerations only showing one record per location. Also, these aren't the real table names.
[tt]
TABLE Details
--------------
RunDate WeekNo Location
2/13/2006 21 SF
2/13/2006 21 LA
2/13/2006 21 SD
TABLE Location
--------------
Location (Primary Key)
SF
LA
SD
SJ
SR
--Actual Result--
Location.Location Details.Location
SF SF
LA LA
SD SD
--Needed Result--
Location.Location Details.Location
SF SF
LA LA
SD SD
SJ [red][null][/red]
SR [red][null][/red]
------------------------------------
[/tt]
Here is the query
QUERY Summary
--------------
[tt]SELECT Location.Location, Details.Location
FROM Location LEFT JOIN Details ON Location.Location = Details.Location
WHERE Details.WeekNo=21
GROUP BY Location.Location, Details.Location;[/tt]
When the query is working, I plan to display WeekNo and Sum of Location rather than having a where clause.