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 » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query Help



 
 
Thread Tools Display Modes
  #1  
Old September 23rd, 2009, 03:57 PM posted to microsoft.public.access.queries
booner
external usenet poster
 
Posts: 3
Default Query Help

I have 3 tables ... 1 table list of devices ... 2 other tables contain
references to those devices.

Schema Overview:
Devices - Id - AutoNumber
CSDevices - DeviceID - foreign key to Id of Devices
FSDevices - DeviceID - foreign key to Id of Devices

What I want to get is a distinct list of devices used. I created this
query - and for smaller data sets works just fine:

SELECT DISTINCT Devices.* FROM FSDevices,Devices,CSDevices WHERE
Devices.Id=CSDevices.DeviceId OR Devices.Id=FSDevices.DeviceId

However, when there are lots of CSDevices and FSDevices - the query seems to
lock up (runs for a very, very, very long time).

So looking for a better way to generate this list.

Any/all help much appreciated.

BBB


  #2  
Old September 23rd, 2009, 04:05 PM posted to microsoft.public.access.queries
Jeff Boyce
external usenet poster
 
Posts: 8,621
Default Query Help

I may be missing something...

If your first table ([Devices]) holds one record per device, wouldn't that
be the place to get a list of each device?

Regards

Jeff Boyce
Microsoft Office/Access MVP


"booner" wrote in message
m...
I have 3 tables ... 1 table list of devices ... 2 other tables contain
references to those devices.

Schema Overview:
Devices - Id - AutoNumber
CSDevices - DeviceID - foreign key to Id of Devices
FSDevices - DeviceID - foreign key to Id of Devices

What I want to get is a distinct list of devices used. I created this
query - and for smaller data sets works just fine:

SELECT DISTINCT Devices.* FROM FSDevices,Devices,CSDevices WHERE
Devices.Id=CSDevices.DeviceId OR Devices.Id=FSDevices.DeviceId

However, when there are lots of CSDevices and FSDevices - the query seems
to lock up (runs for a very, very, very long time).

So looking for a better way to generate this list.

Any/all help much appreciated.

BBB




  #3  
Old September 23rd, 2009, 04:20 PM posted to microsoft.public.access.queries
booner
external usenet poster
 
Posts: 3
Default Query Help

I probably wasn't clear ... devices is reference data - csdevices,
fsdevices - are which devices are actually in use.

I think I have it now:

SELECT DISTINCT Devices.* FROM CSDevices,Devices WHERE
CSDevices.DeviceId=Devices.Id UNION SELECT DISTINCT Devices.* FROM
FSDevices,Devices WHERE FSDevices.DeviceId=Devices.Id

This gets me same data set - but much faster - and works on small and large
data sets.


"Jeff Boyce" wrote in message
...
I may be missing something...

If your first table ([Devices]) holds one record per device, wouldn't that
be the place to get a list of each device?

Regards

Jeff Boyce
Microsoft Office/Access MVP


"booner" wrote in message
m...
I have 3 tables ... 1 table list of devices ... 2 other tables contain
references to those devices.

Schema Overview:
Devices - Id - AutoNumber
CSDevices - DeviceID - foreign key to Id of Devices
FSDevices - DeviceID - foreign key to Id of Devices

What I want to get is a distinct list of devices used. I created this
query - and for smaller data sets works just fine:

SELECT DISTINCT Devices.* FROM FSDevices,Devices,CSDevices WHERE
Devices.Id=CSDevices.DeviceId OR Devices.Id=FSDevices.DeviceId

However, when there are lots of CSDevices and FSDevices - the query seems
to lock up (runs for a very, very, very long time).

So looking for a better way to generate this list.

Any/all help much appreciated.

BBB






  #4  
Old September 23rd, 2009, 05:50 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Query Help

It might be even faster if you use this variant.

SELECT Devices.*
FROM CSDevices INNER JOIN Devices
ON CSDevices.DeviceId=Devices.Id
UNION
SELECT Devices.*
FROM FSDevices INNER JOIN Devices
ON FSDevices.DeviceId=Devices.Id

Union will strip out duplicates so that only gets done once instead of once in
each query and then again when the UNION executes.

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

booner wrote:
I probably wasn't clear ... devices is reference data - csdevices,
fsdevices - are which devices are actually in use.

I think I have it now:

SELECT DISTINCT Devices.* FROM CSDevices,Devices WHERE
CSDevices.DeviceId=Devices.Id UNION SELECT DISTINCT Devices.* FROM
FSDevices,Devices WHERE FSDevices.DeviceId=Devices.Id

This gets me same data set - but much faster - and works on small and large
data sets.


"Jeff Boyce" wrote in message
...
I may be missing something...

If your first table ([Devices]) holds one record per device, wouldn't that
be the place to get a list of each device?

Regards

Jeff Boyce
Microsoft Office/Access MVP


"booner" wrote in message
m...
I have 3 tables ... 1 table list of devices ... 2 other tables contain
references to those devices.

Schema Overview:
Devices - Id - AutoNumber
CSDevices - DeviceID - foreign key to Id of Devices
FSDevices - DeviceID - foreign key to Id of Devices

What I want to get is a distinct list of devices used. I created this
query - and for smaller data sets works just fine:

SELECT DISTINCT Devices.* FROM FSDevices,Devices,CSDevices WHERE
Devices.Id=CSDevices.DeviceId OR Devices.Id=FSDevices.DeviceId

However, when there are lots of CSDevices and FSDevices - the query seems
to lock up (runs for a very, very, very long time).

So looking for a better way to generate this list.

Any/all help much appreciated.

BBB





  #5  
Old September 23rd, 2009, 07:03 PM posted to microsoft.public.access.queries
booner
external usenet poster
 
Posts: 3
Default Query Help

Excellent point!

"John Spencer" wrote in message
...
It might be even faster if you use this variant.

SELECT Devices.*
FROM CSDevices INNER JOIN Devices
ON CSDevices.DeviceId=Devices.Id
UNION
SELECT Devices.*
FROM FSDevices INNER JOIN Devices
ON FSDevices.DeviceId=Devices.Id

Union will strip out duplicates so that only gets done once instead of
once in each query and then again when the UNION executes.

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

booner wrote:
I probably wasn't clear ... devices is reference data - csdevices,
fsdevices - are which devices are actually in use.

I think I have it now:

SELECT DISTINCT Devices.* FROM CSDevices,Devices WHERE
CSDevices.DeviceId=Devices.Id UNION SELECT DISTINCT Devices.* FROM
FSDevices,Devices WHERE FSDevices.DeviceId=Devices.Id

This gets me same data set - but much faster - and works on small and
large data sets.


"Jeff Boyce" wrote in message
...
I may be missing something...

If your first table ([Devices]) holds one record per device, wouldn't
that be the place to get a list of each device?

Regards

Jeff Boyce
Microsoft Office/Access MVP


"booner" wrote in message
m...
I have 3 tables ... 1 table list of devices ... 2 other tables contain
references to those devices.

Schema Overview:
Devices - Id - AutoNumber
CSDevices - DeviceID - foreign key to Id of Devices
FSDevices - DeviceID - foreign key to Id of Devices

What I want to get is a distinct list of devices used. I created this
query - and for smaller data sets works just fine:

SELECT DISTINCT Devices.* FROM FSDevices,Devices,CSDevices WHERE
Devices.Id=CSDevices.DeviceId OR Devices.Id=FSDevices.DeviceId

However, when there are lots of CSDevices and FSDevices - the query
seems to lock up (runs for a very, very, very long time).

So looking for a better way to generate this list.

Any/all help much appreciated.

BBB





 




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 03:02 PM.


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