Results 1 to 9 of 9
  1. #1
    jdcollins is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    5

    Subquery comparing two fields

    I am trying to complete a query with:



    -Product Name
    -Quantity on Hand
    -Reorder Level

    I only want the query to return the product name when the Quantity Level is below the Reorder Level.

    Should be pretty simple, I think, but I am completely new to subqueries.

    Any help would be great!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Not sure what you mean by subquery, as you don't need one.

    SELECT *
    FROM TableName
    WHERE QuantityOnHand < ReorderLevel
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jdcollins is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    5
    Sorry, just confused the terminology.

    I tried that but got a syntax error (actually said it was a syntax within the subquery).

    SELECT *
    FROM [Product Table]
    WHERE [Quantity on Hand] < [Reorder Level]

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    There should be no error if those are fields in the table. Can you post the db, or a representative sample?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jdcollins is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    5
    I've attached the file... the query is called "low product query"

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I get no error adding the criteria:

    SELECT [Product Table].[Product Name], [Product Table].[Quantity on Hand], [Product Table].[Reorder Level]
    FROM [Product Table] INNER JOIN [Supplier Table] ON [Product Table].[Supplier Number] = [Supplier Table].[Supplier Number]
    WHERE [Product Table].[Quantity on Hand]<[Reorder Level]

    The spaces in your names are not worth the trouble in the long run.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jdcollins is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    5
    I am still getting a syntax error...am I supposed to be adding that to the criteria under Product Name? I've attached a screenshot... I'm obviously doing something wrong!

    I agree about the spaces, but they weren't my idea (this is actually an assignment template I am working off of).

    Thanks for your patience!

  8. #8
    jdcollins is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    5
    On a whim, I just tried adding:

    [Quantity on Hand]<[Reorder Level] to the criteria field and that worked fine.... maybe this is an improvement to Access 2010???

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    The SQL I posted was the entire query. The criteria would simply have looked like:

    <[Reorder Level]

    In the Quantity on Hand field.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. SQL SubQuery Does Not Work
    By saascuba in forum Access
    Replies: 3
    Last Post: 11-04-2010, 01:59 PM
  2. Subquery
    By combine21 in forum Queries
    Replies: 2
    Last Post: 09-17-2010, 04:33 PM
  3. Update from Subquery
    By JoshS in forum Queries
    Replies: 0
    Last Post: 04-28-2010, 07:45 AM
  4. Comparing fields in Access
    By flames8889 in forum Queries
    Replies: 2
    Last Post: 04-20-2010, 11:55 AM
  5. Comparing between fields
    By Dashin in forum Queries
    Replies: 0
    Last Post: 02-13-2009, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums