Results 1 to 12 of 12
  1. #1
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83

    Comparing two tables to find missing items

    I have to two tables called Location and Sell.



    The Location table list location of the item. The Sell table list item I Sell.

    How would I show item that I don't sell by item and location

    Would I use Is Null

    If it is Null, then how can I show "NO" in the table
    Attached Files Attached Files
    Last edited by Jerseynjphillypa; 05-16-2012 at 05:37 AM. Reason: not solved

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you tried out the "Unmatched Query Wizard"?

  3. #3
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83
    Thank you for your suggestion

    Yes that's how I got "Is Null", but now I would like for it to say NO or a message like I don't sell this item

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Since you solved your issue,would you care to share your solution with others that read this forum?

  5. #5
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83
    Sorry, i taught I was able to solve it myself

    This is what I did, iif(isnull([Sell]),"NO",[Sell]) but it still shows the Sell Items.

    I just care about the items I don't sell.

    So I would like to see only Null values and replace it with a text string

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Try the UNmatched query wizard as Allan suggested - - and use Is Null to select onlythose records that "haven't been Sold".

    Format along this line

    SELECT TablA.Fld1, TablA.Fld2, TablA.Fld3, TablA.Fld4
    FROM TablA LEFT JOIN TablB ON TablA.id = TablB.id
    WHERE (((TablB.id) Is Null));

  7. #7
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83
    Thanks for the help orange, I tried what Allen suggested but now I would like to replace the Unmatched items with a text field to say "NO"

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Show your query sql.

    Go to your query window, select SQL view; copy it and paste it in your post.

  9. #9
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83
    Code:
    SELECT Location.Item, Location.Location, Sell.SellFROM Location LEFT JOIN Sell ON Location.Item = Sell.Item
    WHERE (((Sell.Sell) Is Null));

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    I have 2003 so can not open your accdb file to see what your table layouts are.
    Normally you would have tables Location and Sell each with a Primary key.

    Location may look like this

    Location(id autonumber, Item text, Location text,...other fields specific to Location..)
    Sell(id autonumber, Loc_FK number, Salesman text, ..other fields specific to Sell...)

    Your tables would be related by a relationship between Location.Id and Sell.Loc_FK which would mean "Locations that has been Sold can be found by
    using the FK field in SELL to find records in Location.

    revised query using my tables

    Code:
    SELECT Location.id, Location.item, Location.Location, IIf(IsNull([sell_FK]),"NO",[Sell_FK]) AS MyDisplayValue
    FROM Location LEFT JOIN Sell ON Location.id = Sell.sell_Fk
    WHERE sell.sell_fk is null;
    The attached jpg shows the table values and the result of the revised query.
    Attached Thumbnails Attached Thumbnails LocationSell.jpg  

  11. #11
    Jerseynjphillypa is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    83
    Thank you for your help orange and posting an example

  12. #12
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848

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

Similar Threads

  1. Comparing two tables
    By jcarstens in forum Queries
    Replies: 3
    Last Post: 05-07-2012, 10:06 PM
  2. Comparing two tables.
    By elmister in forum Access
    Replies: 11
    Last Post: 08-24-2011, 11:59 AM
  3. Comparing two tables.
    By elmister in forum Queries
    Replies: 1
    Last Post: 08-22-2011, 05:32 PM
  4. Comparing Records in two (2) Tables.
    By RalphJ in forum Programming
    Replies: 19
    Last Post: 04-19-2011, 02:50 AM
  5. Comparing tables
    By YoungWolf in forum Database Design
    Replies: 7
    Last Post: 01-10-2011, 11: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