Connecting Tech Pros Worldwide Help | Site Map

Filtering

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 03:01 PM
Elias Farah
Guest
 
Posts: n/a
Default Filtering

Hello All,

I hope someone can give me (and other keen access enthusiasts) some
helpful information to explain how to most efficiently filter Queries
& subqueies.

Consider this common simple situation:

1. OrderTable
OrderID - Indexed (PK)
VendorID - Indexed
etc

2. OrderLineTable
OrderLineID - Indexed (PK)
OrderID - Indexed
ProductID - Indexed
Price
Qty
TaxRate

3. VendorTable
VendorID - Indexed (PK)
VendorName etc.

4. ProductTable
ProductID - Indexed (PK)
ProductName etc

OrderLineQuery
OrderLineID
OrderID
ProductID
LineTotal: [Price]*[Qty]*[TaxRate]

OrderTotalQuery
OrderID
OrderTotal: Sum(LineTotal)


Now, If you want to query all Invoices, which include, say
ProductID=1000, and display the [OrderTotal], and perhaps Filter by
Vendor as Optional, and display[VendorName], you need yet another
Query to link the information.

Lets say there is 20,000 invoices, and 60,000 invoice lines, and
ProductID=1000 occurs on 12,000 invoices. Really, nothing too big!

Should I filter on ProductID:

a) OrderLineQuery Field, [OrderLineQuery].[ProductID]?

b) Should I create a Join between [OrderLineQuery].[ProductID] and
[ProductTable].[ProductID], and Filter
[ProductTable].[ProductID]?

Summing up the invoices can take 2 seconds, so it's inefficient to
have the OrderTotalQuery execute more than is required.

I don't want the OrderLineQuery to run too many times, because it
performing calcs on decimal currency, and tax rates - on 60,000 lines,
if unfiltered!

I am so confused, as I seem to be getting lost in the field
manifestation throughout the Subqueries - and when filtering more
fields simultaneously, ie, price, date, vendor, ordertotals etc etc -
The query can take 30 seconds, instead of a fraction of a second.


It's hard to explain.........

Look forward to someone giving me some good advice!


Regards



Elias Farah.

  #2  
Old November 12th, 2005, 03:03 PM
Allen Browne
Guest
 
Posts: n/a
Default Re: Filtering

Use the JOIN between the 4 tables. Access/JET is very good at choosing the
best query plan, and joins are generally the most efficient approach.

Include both the ProductID and VendorID in your query. You can add the
criteria as needed. In this way, the calculation is needed only for the
selected rows (rather than selecting and calculating all rows and then
culling them). For example, if this is for a form, you could assign the new
query statement (including the joins and criteria) to the RecordSource of
the form. I've generally found that reassigning a SQL statement dynamically
like that is much more efficient and flexible than subqueries or stacked
queries.

Your data structure looks good, though there is no need to index your
foreign keys. If you create relations involving referential integrity,
Access automatically creates indexes to manage the RI.



--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Elias Farah" <longnose@hotmail.com> wrote in message
news:c6cfe5a6.0311030555.5ed42bd7@posting.google.c om...[color=blue]
> Hello All,
>
> I hope someone can give me (and other keen access enthusiasts) some
> helpful information to explain how to most efficiently filter Queries
> & subqueies.
>
> Consider this common simple situation:
>
> 1. OrderTable
> OrderID - Indexed (PK)
> VendorID - Indexed
> etc
>
> 2. OrderLineTable
> OrderLineID - Indexed (PK)
> OrderID - Indexed
> ProductID - Indexed
> Price
> Qty
> TaxRate
>
> 3. VendorTable
> VendorID - Indexed (PK)
> VendorName etc.
>
> 4. ProductTable
> ProductID - Indexed (PK)
> ProductName etc
>
> OrderLineQuery
> OrderLineID
> OrderID
> ProductID
> LineTotal: [Price]*[Qty]*[TaxRate]
>
> OrderTotalQuery
> OrderID
> OrderTotal: Sum(LineTotal)
>
>
> Now, If you want to query all Invoices, which include, say
> ProductID=1000, and display the [OrderTotal], and perhaps Filter by
> Vendor as Optional, and display[VendorName], you need yet another
> Query to link the information.
>
> Lets say there is 20,000 invoices, and 60,000 invoice lines, and
> ProductID=1000 occurs on 12,000 invoices. Really, nothing too big!
>
> Should I filter on ProductID:
>
> a) OrderLineQuery Field, [OrderLineQuery].[ProductID]?
>
> b) Should I create a Join between [OrderLineQuery].[ProductID] and
> [ProductTable].[ProductID], and Filter
> [ProductTable].[ProductID]?
>
> Summing up the invoices can take 2 seconds, so it's inefficient to
> have the OrderTotalQuery execute more than is required.
>
> I don't want the OrderLineQuery to run too many times, because it
> performing calcs on decimal currency, and tax rates - on 60,000 lines,
> if unfiltered!
>
> I am so confused, as I seem to be getting lost in the field
> manifestation throughout the Subqueries - and when filtering more
> fields simultaneously, ie, price, date, vendor, ordertotals etc etc -
> The query can take 30 seconds, instead of a fraction of a second.
>
>
> It's hard to explain.........
>
> Look forward to someone giving me some good advice!
>
>
> Regards
>
>
>
> Elias Farah.[/color]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.