Results 1 to 5 of 5
  1. #1
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    149

    Query with conditional table

    Hi,
    I am not sure how to describe my problem, which makes it very hard to define a search term to do a general search.
    I have three tables:
    Product; Price
    Customer; Product
    Customer; Product; Special Price

    I want to change the Price so I constructed a query - All customers who buy Product X - So the query returns a nice list of all the relevant customers.
    But some customers have a special price so I need a query which lists all customers who buy Product X AND if they have a special price.



    But if I add the special price to the query I get only those customers who buy Product X AND have a special price - the non-special price customers are not listed??

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,144
    Post up a picture of your tables or some sample table data for each table.
    I don't know why you would need two tables for customers and products, then customers and products and special price.

    Surely just enter a special price or don't? Then you query becomes simple with an IIf() clause.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    Agree with Minty, you only need the one Customer; Product; Special Price table and leave special price blank if not specified

    You have described the problem but given no information on where you get the problem i.e.

    But if I add the special price to the query I get only those customers who buy Product X AND have a special price - the non-special price customers are not listed??

    So what is the sql to the query?


  4. #4
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    149
    Sorry if I was a bit unclear - but full marks to Minty - an IIf did the trick - many thanks

  5. #5
    Join Date
    Apr 2017
    Posts
    1,776
    Quote Originally Posted by TOPSie View Post
    Sorry if I was a bit unclear - but full marks to Minty - an IIf did the trick - many thanks
    Or you use a query like
    Code:
    SELECT cust.Customer, cust.Product, prod.Price AS ProductPrice, sp.SpecialPrice FROM (tCustomers.Customer cust LEFT JOIN tProducts prod ON prod.Product = cust.Product) LEFT JOIN tCpecialPrices sp ON sp.Customer = cust.Customer AND sp.Product = cust.Product
    The query returns Null when the price or special price is undetermined for given product and customer. (You can add a WHERE clause to limit the query to specific customer.)

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

Similar Threads

  1. Conditional Query with conditional results
    By Jeff_in_KCMO in forum Queries
    Replies: 4
    Last Post: 09-10-2014, 01:44 PM
  2. Replies: 3
    Last Post: 12-11-2012, 06:27 PM
  3. Conditional list table
    By josnow in forum Forms
    Replies: 1
    Last Post: 11-24-2012, 02:53 PM
  4. Replies: 2
    Last Post: 09-08-2011, 01:10 PM
  5. Conditional Table relationship?
    By srf.ucd in forum Database Design
    Replies: 1
    Last Post: 05-13-2011, 10:32 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