Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 573879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:46:17+00:00 2026-05-13T13:46:17+00:00

This shows me all the first names and last names that have exactly two

  • 0

This shows me all the first names and last names that have exactly two entries that are identical

SELECT `firstname`,`lastname`,COUNT(*) AS Count 
FROM `people` 
GROUP BY `firstname`,`lastname`
HAVING Count = 2

How do I turn this into a DELETE FROM WHERE statement with a LIMIT to only remove one of each of the entries and leave the other one.

okay this appears to be way to technical i’m just going to do it in a php while loop

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:46:17+00:00Added an answer on May 13, 2026 at 1:46 pm

    You can create a table with 1 record of each of the duplicates: Then delete all the dup records from the people table and then re-insert the dup records.

    -- Setup for example
    create table people (fname varchar(10), lname varchar(10));
    
    insert into people values ('Bob', 'Newhart');
    insert into people values ('Bob', 'Newhart');
    insert into people values ('Bill', 'Cosby');
    insert into people values ('Jim', 'Gaffigan');
    insert into people values ('Jim', 'Gaffigan');
    insert into people values ('Adam', 'Sandler');
    
    -- Show table with duplicates
    select * from people;
    
    -- Create table with one version of each duplicate record
    create table dups as 
        select distinct fname, lname, count(*) 
        from people group by fname, lname 
        having count(*) > 1;
    
    -- Delete all matching duplicate records
    delete people from people inner join dups 
    on people.fname = dups.fname AND 
       people.lname = dups.lname;
    
    -- Insert single record of each dup back into table
    insert into people select fname, lname from dups;
    
    -- Show Fixed table
    select * from people;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that shows all the images inside 'images' directory but it
I have a query now that shows me all the calls between this time,
I have a database with first names and last names. I select some of
i have this query but this shows column does not exist SELECT p.content, (select
This shows what I have and want: So yeah as you can see I
This question shows the usage of **var = new Object(); and that's something totally
So I have these tables: STUDENTS: Student ID - First name - Last name
I have a PHP code that actively generates a Select input with 5 different
I have an entity class User that contains information such as username, first name,
Let's say I have a Person table with a FirstName and LastName column. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.