A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query



 
 
Thread Tools Display Modes
  #1  
Old September 2nd, 2009, 08:36 PM posted to microsoft.public.access.gettingstarted
QUERIES
external usenet poster
 
Posts: 2
Default Query

I have 3 tables (TRUCK, DRIVER and ASSIGNED). ASSIGNED is used to record
which DRIVER has which TRUCK by the date. I have more trucks than drivers.
What is the best approach to list which trucks currently have no drivers.
  #2  
Old September 2nd, 2009, 09:19 PM posted to microsoft.public.access.gettingstarted
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Query

Try this putting your table and field names --
SELECT TRUCK.TruckID
FROM TRUCK LEFT JOIN ASSIGNED ON TRUCK.TruckID = ASSIGNED.TruckID
WHERE (ASSIGNED.TruckID Is Null) AND (ASSIGNED.WorkDate = Date());

--
Build a little, test a little.


"Queries" wrote:

I have 3 tables (TRUCK, DRIVER and ASSIGNED). ASSIGNED is used to record
which DRIVER has which TRUCK by the date. I have more trucks than drivers.
What is the best approach to list which trucks currently have no drivers.

  #3  
Old September 2nd, 2009, 09:25 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default Query


SELECT TruckNumber
FROM Truck
WHERE TruckNumber NOT IN (
SELECT TruckNumber
FROM Truck
WHERE DateField = Date())

In query design view
== Add the Truck table
== Add the fields you want to see
== Under TruckNumber (or what ever the identifying field is) enter something
like the following into the criteria.
NOT IN (SELECT TruckNumber FROM Truck WHERE [Datefield] Date())

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Queries wrote:
I have 3 tables (TRUCK, DRIVER and ASSIGNED). ASSIGNED is used to record
which DRIVER has which TRUCK by the date. I have more trucks than drivers.
What is the best approach to list which trucks currently have no drivers.

  #4  
Old September 2nd, 2009, 09:34 PM posted to microsoft.public.access.gettingstarted
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Query

On Wed, 2 Sep 2009 12:36:02 -0700, Queries
wrote:

I have 3 tables (TRUCK, DRIVER and ASSIGNED). ASSIGNED is used to record
which DRIVER has which TRUCK by the date. I have more trucks than drivers.
What is the best approach to list which trucks currently have no drivers.


SELECT whatever fields you want to see
FROM TRUCK
WHERE NOT EXISTS
(SELECT TruckID FROM Assigned WHERE some appropriate date criteria on the
date field or fields in ASSIGNED)

--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:06 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.