Results 1 to 7 of 7
  1. #1
    NPT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    3

    Delete duplicate records if a field matches certain criteria

    Hi



    I have a table called "Sponsor_Sec" with 3 columns.

    1) secid
    2) cusip
    3) flag

    Each secid could have either

    a) one cusip with either flag "C" or "S"
    b) two cusip with both flags "C" and "S"

    I need a query that can create a new table called "Sponsor_Sec_Post" by only including records that only includes unique secids (a) and in the event there is a duplicate, include the one with the flag "C" (b)

    In other words I need to remove any duplicate records where the flag is "S". Keep all other records.


    I have attached a screenshot of the table.


    Hope somone can help me with this.

    Thanks
    NPT
    Attached Thumbnails Attached Thumbnails Capture.JPG  

  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
    53,598
    What makes record a 'duplicate', repeats of just Secid? cusip will not duplicate? http://office.microsoft.com/en-us/ac...010341696.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.

  3. #3
    NPT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    3
    Yes. Only repeat of secid makes a record duplicate. Duplicates in cusp are OK. Thanks

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,598
    Did the reference help?
    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.

  5. #5
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Make this query & keep it.
    qrySecID_1


    Code:
    SELECT 
    	Sponsor_Sec.SecID, 
    	Count(Sponsor_Sec.flag) AS CountOfflag
    FROM 
    	Sponsor_Sec
    GROUP BY 
    	Sponsor_Sec.SecID
    HAVING 
    	(((Count(Sponsor_Sec.flag))=1));

    Make this query & keep it.

    qrySecID_2
    Code:
    SELECT 
    	Sponsor_Sec.SecID, 
    	Count(Sponsor_Sec.flag) AS CountOfflag
    FROM 
    	Sponsor_Sec
    GROUP BY 
    	Sponsor_Sec.SecID
    HAVING 
    	(((Count(Sponsor_Sec.flag))=2));

    Run this query first.

    qrySecID_1_MakeTable

    Code:
    SELECT 
    	Sponsor_Sec.SecID, 
    	Sponsor_Sec.cusip, 
    	Sponsor_Sec.flag 
    INTO 
    	Sponsor_Sec_Post
    FROM 
    	Sponsor_Sec 
    	INNER JOIN 
    	qrySecID_1 
    	ON 
    	Sponsor_Sec.SecID = qrySecID_1.SecID;
    Run this query second.

    qrySecID_2_AppendTable


    Code:
    INSERT INTO 
    	Sponsor_Sec_Post ( SecID, cusip, flag )
    	SELECT 
    		Sponsor_Sec.SecID, 
    		Sponsor_Sec.cusip, 
    		Sponsor_Sec.flag
    	FROM 
    		Sponsor_Sec 
    		INNER JOIN 
    		qrySecID_2 
    		ON 
    		Sponsor_Sec.SecID = qrySecID_2.SecID
    WHERE 
    	(((Sponsor_Sec.flag)="C"));

    Thanks

  6. #6
    NPT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    3
    Thanks recyan. This worked very well. Appreciate your assitance.

    NPT

  7. #7
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Glad you got things working.

    Thanks.

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

Similar Threads

  1. Replies: 3
    Last Post: 02-19-2013, 08:15 AM
  2. Replies: 1
    Last Post: 01-30-2013, 03:27 PM
  3. Replies: 2
    Last Post: 04-13-2012, 12:53 AM
  4. Delete Duplicate Records Based on Criteria
    By chadd in forum Queries
    Replies: 2
    Last Post: 02-07-2012, 04:24 PM
  5. Delete duplicate records
    By Zukster in forum Queries
    Replies: 1
    Last Post: 08-26-2009, 03:14 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