开发者

How to create a query to get all records from one table and fill in field information from a second table with a where statement?

I have two tables. One is called prem and contains all ids that exist in a system, and JimsQueryByColl which has most of those ids with various information attached. I am trying to create a single query that will include all of the ids from prem, and all of the records from the JimsQueryByColl where JimsQueryByColl.Collector = "Frederick Road". The current query I have is as follows but only gives the latter part of the information (without the ids from the prem that don't appear in a list of ids with Frederick Road in the collector collumn):

SELECT Prem.meter_miu_id, JimsQueryByColl.*, Prem.longitude, Prem.latitude

FROM Prem LEFT JOIN JimsQueryByColl ON Prem.meter_miu_id = JimsQueryByColl.[MIU ID]

WHERE (((JimsQueryByColl.Collector)="Frederick Road"))

Normally the Left Join would have achieved what i desire but the where statement is making it where the ids that would have blank information for all but the *Prem.meter_miu_id* field are not included. I have tried to add an "or JimsQueryByColl.Collector IS NULL" to the WHERE statement but that didn't get the correct result.

The current two query method I have for getting the right information are titled FredrickRoad and Query3:

FredrickRoad-

SELECT JimsQueryByColl.* FROM JimsQueryByColl WHERE (((JimsQueryByColl.Collector)="Frederick Road"))

Followed by Q开发者_如何学编程uery3 -

SELECT Prem.meter_miu_id, JimsQueryByColl.*, Prem.longitude, Prem.latitude FROM Prem LEFT JOIN JimsQueryByColl ON Prem.meter_miu_id = JimsQueryByColl.[MIU ID] WHERE (((JimsQueryByColl.Collector)="Frederick Road"));

But I would like to do this in one step if possible. I hope I have written this clearly and if someone needs clarification just ask.

Current Solution

SELECT Prem.meter_miu_id, JimsQueryByColl.*, Prem.longitude, Prem.latitude

Into FrederickRoad FROM Prem LEFT JOIN JimsQueryByColl ON (Prem.meter_miu_id = JimsQueryByColl.[MIU ID]

AND JimsQueryByColl.Collector="Frederick

Road")

This gets around the odd bug/error I'm getting with the query since it puts it into a table and doesn't deal with the query directly again. I would however love to know what is causing the problems I'm having.


Try:

SELECT Prem.meter_miu_id, JimsQueryByColl.*, Prem.longitude, Prem.latitude
FROM Prem LEFT JOIN JimsQueryByColl 
ON (Prem.meter_miu_id = JimsQueryByColl.[MIU ID] 
AND JimsQueryByColl.Collector="Frederick Road")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜