Results 1 to 2 of 2
  1. #1
    Huddle is offline Competent Performer
    Windows XP Access 2010 64bit
    Join Date
    Jun 2010
    Posts
    318

    Want to remove duplicates from a SQL code

    I have the below code but I want to add a grouping to it so that if there is a duplicate building number it will not list it. Is there a way to add a grouping into the code to do this?

    SELECT Q_PI_Qrtly_Insp_Ct_Range.District, Q_PI_Qrtly_Insp_Ct_Range.Bldg_Number, Q_PI_Qrtly_Insp_Ct_Range.Bldg_Name, Q_PI_Qrtly_Insp_Ct_Range.Address, Q_PI_Qrtly_Insp_Ct_Range.City, Q_PI_Qrtly_Insp_Ct_Range.State, Q_PI_Qrtly_Insp_Ct_Range.FSL, Count(Q_PI_Qrtly_Insp_Ct_Range.Insp_Date) AS CountOfInsp_Date, Q_PI_Qrtly_Insp_Ct_Range.Due, Lookup_Tbl_Commander_Inspector.Commander
    FROM Lookup_Tbl_Commander_Inspector RIGHT JOIN (Q_PI_Qrtly_Insp_Ct_Range LEFT JOIN Tbl_Bldg_Insp_Connector ON Q_PI_Qrtly_Insp_Ct_Range.Bldg_Number = Tbl_Bldg_Insp_Connector.Connecting_Bldg) ON Lookup_Tbl_Commander_Inspector.Inspector = Tbl_Bldg_Insp_Connector.Connecting_Inspector
    GROUP BY Q_PI_Qrtly_Insp_Ct_Range.District, Q_PI_Qrtly_Insp_Ct_Range.Bldg_Number, Q_PI_Qrtly_Insp_Ct_Range.Bldg_Name, Q_PI_Qrtly_Insp_Ct_Range.Address, Q_PI_Qrtly_Insp_Ct_Range.City, Q_PI_Qrtly_Insp_Ct_Range.State, Q_PI_Qrtly_Insp_Ct_Range.FSL, Q_PI_Qrtly_Insp_Ct_Range.Due, Lookup_Tbl_Commander_Inspector.Commander;
    UNION SELECT Q_PI_Qrtly_Insp_Ct_Range_Null.District, Q_PI_Qrtly_Insp_Ct_Range_Null.Bldg_Number, Q_PI_Qrtly_Insp_Ct_Range_Null.Bldg_Name, Q_PI_Qrtly_Insp_Ct_Range_Null.Address, Q_PI_Qrtly_Insp_Ct_Range_Null.City, Q_PI_Qrtly_Insp_Ct_Range_Null.State, Q_PI_Qrtly_Insp_Ct_Range_Null.FSL, " " AS Blank, Q_PI_Qrtly_Insp_Ct_Range_Null.Due, Lookup_Tbl_Commander_Inspector.Commander
    FROM Lookup_Tbl_Commander_Inspector RIGHT JOIN (Q_PI_Qrtly_Insp_Ct_Range_Null LEFT JOIN Tbl_Bldg_Insp_Connector ON Q_PI_Qrtly_Insp_Ct_Range_Null.Bldg_Number = Tbl_Bldg_Insp_Connector.Connecting_Bldg) ON Lookup_Tbl_Commander_Inspector.Inspector = Tbl_Bldg_Insp_Connector.Connecting_Inspector
    GROUP BY Q_PI_Qrtly_Insp_Ct_Range_Null.District, Q_PI_Qrtly_Insp_Ct_Range_Null.Bldg_Number, Q_PI_Qrtly_Insp_Ct_Range_Null.Bldg_Name, Q_PI_Qrtly_Insp_Ct_Range_Null.Address, Q_PI_Qrtly_Insp_Ct_Range_Null.City, Q_PI_Qrtly_Insp_Ct_Range_Null.State, Q_PI_Qrtly_Insp_Ct_Range_Null.FSL, Q_PI_Qrtly_Insp_Ct_Range_Null.Due, Lookup_Tbl_Commander_Inspector.Commander;

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    UNION will not allow duplicate records. UNION ALL will allow duplicate records. If any field has different value then the record is not a duplicate and grouping will not eliminate.
    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. Remove close duplicates from query
    By prichardson in forum Queries
    Replies: 2
    Last Post: 02-15-2013, 12:40 PM
  2. Query to Sum Values and Remove Duplicates
    By noobaccessuser in forum Queries
    Replies: 1
    Last Post: 12-06-2012, 07:12 PM
  3. Replies: 7
    Last Post: 04-15-2011, 08:46 AM
  4. Remove Duplicates Based on Criteria
    By suryaprasad in forum Access
    Replies: 0
    Last Post: 04-07-2011, 10:50 PM
  5. How to remove duplicates
    By TonyBender in forum Access
    Replies: 0
    Last Post: 10-21-2009, 10:27 PM

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