Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:30:58+00:00 2026-06-05T16:30:58+00:00

Here is my access query that I have. Every value that I return is

  • 0

Here is my access query that I have. Every value that I return is required (unfortunately). The worst part of this query, however. Is that it sometimes misses rows that fit the criteria in the WHERE clause. Every optimization I tried to make does not help, or cannot be done in Access (knowing SQL). The WHERE clause, as you can see, checks between three date fields. Here’s the tricky part. For every one row of information in Inventory Masterfile, there are five rows in Inventory Stores (one for each “BranchID”) and the Date columns I’m checking against in the where clause, could have the date updated in any one of those five rows, to the one row in Inventory Masterfile. Does anyone have any suggestions at all that could help me? I’ve been debugging for weeks and am at the end of my wits on this one.

SELECT a.Item1,im.Secondary,im.Description,im.Author_Artist,im.RetailPrice,im.CatalogID,im.Publisher, im.Binding,im.PubDate,im.Grouping,im.CategoryId,im.Alt_Category,

(SELECT MAX(ls.OnHand) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1 AND ls.BranchID = 5)) AS 1Stock,

(SELECT MAX(ls.OnHand) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1 AND ls.BranchID = 3)) AS 2Stock,

(SELECT MAX(ls.OnHand) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1 AND ls.BranchID = 4)) AS 3Stock,

(SELECT MAX(ls.Maximum) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1 AND ls.BranchID = 4)) AS Maximum,

(SELECT MAX(ls.LastSold1) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1)) AS LastSold1,

(SELECT MAX(ls.LastUpdate) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1)) AS LastUpdate,

(SELECT MAX(ls.LastReceived) FROM [Inventory Store] ls WHERE (ls.Item1 = a.Item1)) AS LastReceived

FROM [Inventory Store] AS a

INNER JOIN [Inventory Masterfile] im ON a.Item1 = im.Item1

WHERE (a.LastSold1 > #6/12/2012# OR a.LastUpdate > #6/12/2012# OR a.LastReceived > #6/12/2012#)

GROUP BY a.Item1, im.Secondary, im.Description, im.Author_Artist, im.RetailPrice, 
im.CatalogID,im.Publisher, im.Binding,im.PubDate,im.Grouping,im.CategoryId,im.Alt_Category
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:31:00+00:00Added an answer on June 5, 2026 at 4:31 pm

    Try this, you have subqueries and they are slow.

    SELECT a.item1,
           im.secondary,
           im.description,
           im.author_artist,
           im.retailprice,
           im.catalogid,
           im.publisher,
           im.binding,
           im.pubdate,
           im.grouping,
           im.categoryid,
           im.alt_category,
           z.[1stock],
           y.[2stock],
           x.[3stock],
           w.mmaximum,
           v.mlastsold1,
           u.mlastupdate,
           t.mlastreceived
    FROM   (((((((([inventory store] AS a
                   LEFT JOIN (SELECT ls.item1,
                                     Max(ls.onhand) AS [1Stock]
                              FROM   [inventory store] ls
                              WHERE  ls.branchid = 5
                              GROUP  BY ls.item1) AS z
                          ON a.item1 = z.item1)
                  LEFT JOIN (SELECT ls.item1,
                                    Max(ls.onhand) AS [2Stock]
                             FROM   [inventory store] ls
                             WHERE  ls.branchid = 3
                             GROUP  BY ls.item1) AS y
                         ON a.item1 = y.item1)
                 LEFT JOIN (SELECT ls.item1,
                                   Max(ls.onhand) AS [3Stock]
                            FROM   [inventory store] ls
                            WHERE  ls.branchid = 4
                            GROUP  BY ls.item1) AS x
                        ON a.item1 = x.item1)
                LEFT JOIN (SELECT ls.item1,
                                  Max(ls.maximum) AS [mMaximum]
                           FROM   [inventory store] ls
                           WHERE  ls.branchid = 4
                           GROUP  BY ls.item1) AS w
                       ON a.item1 = w.item1)
               LEFT JOIN (SELECT ls.item1,
                                 Max(ls.lastsold1) AS mLastSold1
                          FROM   [inventory store] ls
                          GROUP  BY ls.item1) AS v
                      ON a.item1 = v.item1)
              LEFT JOIN (SELECT ls.item1,
                                Max(ls.lastupdate) AS mLastUpdate
                         FROM   [inventory store] ls
                         GROUP  BY ls.item1) AS u
                     ON a.item1 = u.item1)
             LEFT JOIN (SELECT ls.item1,
                               Max(ls.lastreceived) AS mLastReceived
                        FROM   [inventory store] ls
                        GROUP  BY ls.item1) AS t
                    ON a.item1 = t.item1)
            LEFT JOIN [inventory masterfile] im
                   ON a.item1 = im.item1)
    WHERE  ( a.lastsold1 > #2012/6/12#
              OR a.lastupdate > #2012/6/12#
              OR a.lastreceived > #2012/6/12# )
    GROUP  BY a.item1,
              im.secondary,
              im.description,
              im.author_artist,
              im.retailprice,
              im.catalogid,
              im.publisher,
              im.binding,
              im.pubdate,
              im.grouping,
              im.categoryid,
              im.alt_category,
              z.[1stock],
              y.[2stock],
              x.[3stock],
              w.mmaximum,
              v.mlastsold1,
              u.mlastupdate,
              t.mlastreceived
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query to return random distinct rows from an Access database. Here
So, I have a huge query that I need to run on an Access
I am writing a program that will query an MS access database, return the
I have a project here the goal is to merge multiple Access DB's into
So I'm trying to access this api https://www.clarityaccounting.com/api-docs/ using SUDS. Here is the code
I have read-only access to a database that was set up for a third-party,
I have another SQL/access 2007 question that seems really basic but I'm not sure
SQL beginner here. I have a query which takes around 10 seconds to run,
I have a deadlock problem with two transactions that do not access any common
I'm displaying a set of rows here for every car I have in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.