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 8394033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:57:40+00:00 2026-06-09T19:57:40+00:00

Possible Duplicate: Remove duplicates using only a MySQL query? I have a table with

  • 0

Possible Duplicate:
Remove duplicates using only a MySQL query?

I have a table with different pages but some of them are duplicates. The only way to determine duplicates are by title. I run the code below and it works perfectly:

<?php

mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("old") or die(mysql_error());
$result = mysql_query("SELECT pagetitle, COUNT( * ) c
FROM cms_site_content
GROUP BY pagetitle
HAVING c >1") or die(mysql_error());  
while($row = mysql_fetch_array($result)){
    echo $row['id'].'-'.$row['pagetitle'].'<br />';
}

?>

My question is: How can I erase duplicates and keep only one entry. For example if I have an article called “Duplicate Article” and the result is

Duplicate Article: 3

I want to keep only one.

  • 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-06-09T19:57:41+00:00Added an answer on June 9, 2026 at 7:57 pm

    You’ll want to INNER JOIN the table on itself and delete where the pagetitle values are identical but the primary key (I’m using ID as the identifier) is not.

    Try:

    DELETE c2 FROM `cms_site_content` c1 INNER JOIN
                   `cms_site_content` c2
              ON c1.pagetitle = c2.pagetitle AND c1.ID <> c2.ID
    

    Reference: http://dev.mysql.com/doc/refman/5.0/en/join.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Java Remove Duplicates from an Array? String={3333,4444,5555,5555,1111} Using Delimiter i have put
Possible Duplicate: XmlSerializer: remove unnecessary xsi and xsd namespaces I'm generating some XML using
Possible Duplicates: Remove duplicates in large MySql table Can I extract the extract records
Possible Duplicate: Remove duplicates from a List<T> in C# i have a List like
Possible Duplicate: Can't remove Default.png? I am using Xcode 4, but I am sure
Possible Duplicate: remove attribute of html tag I have some jQuery in my code
Possible Duplicate: How do you remove duplicates from a list in Python whilst preserving
Possible Duplicate: remove duplicate from string in PHP Have a string like: $str =
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: Php: remove all tags, but “a href” in a text Is there

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.