Results 1 to 4 of 4
  1. #1
    mcchung52 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    15

    ummmm... finding duplicate rows

    I have 4 columns in a table:
    id (primary)
    vendor (which is a foreign key for vendor table)
    vendorno (which is actually a product number from that vendor)
    product (which is a foreing key for product table)*



    *I'm separating the vendorno from the product table
    so product table is general in definition so two different vendor
    carrying the same product would point to one product id.
    I don't know if this was a smart move but oh well...

    I want to pull, for a given vendor, all duplicate vendornos
    which cannot happen either with same or different product id
    because vendorno should be a unique number from that vendor.

    I'm currently struggling with this:
    SELECT DISTINCT vendor, vendorno, COUNT(vendorno) AS NumOcc
    FROM vendor_map
    GROUP BY vendor, vendorno
    HAVING (count(vendorno)>1);

    any insight??

    BONUS TIP: if you also know how to call from the vendor table to
    substitute in the final query result the actual name of the vendor
    instead of the id that'll be super!!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Query looks good. What is problem? Error message, wrong results, no results?

    Include the vendor table in the query by join and include the name in the GROUP BY.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    mcchung52 is offline Novice
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    15
    nothing shows up on query. no result.
    I did some manual check and saw that for
    vendor and vendorno distinct combo, there were
    no duplicates so nothing should be returned.

    Then I figured I need to look for a different thing. (sorry...)
    How do I write a query where
    (all vendor, vendorno combo are distinct but) the fourth
    column, product, cannot have a duplicate product id
    within the same vendor?
    ex. for a similar looking vendorno but different, there were
    duplicate product id, which is most likely an erroraneous
    user input.

    this is what I have so far:
    SELECT vendor, vendorno, drug
    FROM vendor_map
    GROUP BY vendor, drug
    HAVING (count(drug)>1);


    June7, can you show me how I do
    that join and group by query?
    Last edited by mcchung52; 02-07-2012 at 02:23 AM.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Building queries with table joins is basic Access functionality. Access Help has guidelines on using the query designer. Here is a tutorial http://office.microsoft.com/en-us/ac...010096320.aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-28-2011, 06:06 AM
  2. Selcting max value with all duplicate rows
    By HectorH in forum Queries
    Replies: 9
    Last Post: 07-21-2011, 12:17 PM
  3. Replies: 3
    Last Post: 05-15-2011, 08:40 AM
  4. finding a value in a recordset
    By TheShabz in forum Programming
    Replies: 9
    Last Post: 04-23-2010, 02:44 PM
  5. Finding Tables
    By Rick West in forum Access
    Replies: 1
    Last Post: 01-06-2010, 10:41 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