Results 1 to 3 of 3
  1. #1
    nd0911 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2017
    Posts
    31

    Query

    Hello,

    I have a sales table:

    SalesId | LeadId | ProductId
    ------------------------------------------
    1 | 1 | 1
    -----------------------------------------
    2 | 1 | 2
    -----------------------------------------
    3 | 2 | 1
    -----------------------------------------
    4 | 3 | 2
    -----------------------------------------
    5 | 2 | 2

    I want to return a query that filter, lets say by productId = 1, that will return all leadId that dont have productId = 1


    so the resulte of our table (if productId = 1) is:

    leadId
    -------
    3
    2

    thank you !!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    make Q1 to pull all leads :
    SELECT tData.LeadId, tData.ProductId FROM tData WHERE (((tData.ProductId)=1))

    make Q2 an OUTER join to show the opposite:
    in the query join Q1 to the data table, join on LeadID,
    bring down LEADid from both tables into the grid,
    dbl-click the join line
    show ALL records in tData , and some in Q1
    set criteria of: Q1.LeadId Is Null

    this will pull all LeadIDs that did not have ProdID =1

    SELECT tData.LeadId, Q1.LeadId
    FROM Q1 RIGHT JOIN tData ON Q1.LeadId = tData.LeadId
    WHERE (((Q1.LeadId) Is Null));

  3. #3
    Join Date
    Apr 2017
    Posts
    1,792
    Code:
    SELECT DISTINCT LeadID FROM YourTable WHERE ProductID Not In (1)

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

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