Solved

Creating a query to show all records from one table plus those that are linked from another

Posted on 2016-10-19
3
52 Views
Last Modified: 2016-10-19
I think my requirement should be quite simple, but just cannot seem to figure it out.

I have two related tables - Drivers and Journeys.
I am trying to construct a query that will list ALL drivers and then details of their future [date>=Date()] journeys if they have any.

Maybe like this....
Joe Bloggs
John Smith - Journey1
John Smith - Journey2
Jack Green
Jim Black - Journey3
Fred White - Journey4
Fred White - Journey5
etc etc...

All my attempts so far will only list drivers if they have a journey.

Hope someone can give me a nudge in the right direction.

Regards
Richard
0
Comment
Question by:rltomalin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 41849890
Try something like:

Selecte Drivers.*, J.*
FROM Drivers
LEFT JOIN (
SELECT Journeys.* FROM Journeys
WHERE [Date] > Date()
) as J ON Drivers.DriverID = J.DriverID
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 41849895
to expand on the previous comment,  in order to get all of the drivers, you have to use a LEFT Join to the Journeys table, but once you assign a criteria to the Journeys table, you end up losing all of the drivers who don't have future journeys.  You might also be able to do:

Selecte Drivers.*, Journeys.*
FROM Drivers
LEFT JOIN Journeys ON Drivers.DriverID = Journeys.DriverID
WHERE (Journeys.[Date] IS NULL) OR (Journeys.[Date] > Date())
0
 

Author Closing Comment

by:rltomalin
ID: 41850214
Hi Dale
The first option works fine - thanks very much.
The second option was similar to my attempts, where the journey criteria limited the list to drivers with journeys.

I think I can work with the first option - will have to build on it now.

Regards
Richard
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question