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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:00:00+00:00 2026-05-27T16:00:00+00:00

I have this table : I would like to delete same rows. For example

  • 0

I have this table :

enter image description here

I would like to delete same rows. For example first five rows are the same, my table should have only one row that includes this data : 40.792274 29.412994 2011-12-21 17:19:52.

So I used the following code :

$query = "SELECT * FROM table GROUP BY date";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){

    $date = $row['date'];
    $lat = $row['latitude'];
    $lon = $row['longitude'];
    $query = "SELECT * FROM table WHERE date='$date' AND latitude='$lat' AND longitude='$lon'";
    $re = mysql_query($query);
    $number = mysql_num_rows($re);
    $number--;

    $query = "DELETE * FROM table WHERE date='$date' AND latitude='$lat' AND longitude='$lon' LIMIT $number";

    mysql_query($query);
}

But this code doesn’t work.. What should I do ?

Edited :

I solved my question :

$query = "SELECT * FROM table GROUP BY date";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){

    $date = $row['date'];
    $lat = $row['latitude'];
    $lon = $row['longitude'];
    $query = "SELECT * FROM table WHERE date='$date' AND latitude=$lat AND    longitude=$lon";
    $re = mysql_query($query);
    $number = mysql_num_rows($re);
    $number--;

    $query = "DELETE FROM table WHERE date='$date' AND latitude=$lat AND longitude=$lon LIMIT $number";

    mysql_query($query);
}

Query lines were incorrect in my first question.

  • 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-27T16:00:01+00:00Added an answer on May 27, 2026 at 4:00 pm

    To remove the duplicate elements, you would use something like this:

    $q = "SELECT date FROM table GROUP BY date"
    $r = mysql_query($r);
    $date = '';
    while($row = mysql_fetch_array($r)){
        $date = $row['date'];
        $q = "SELECT date FROM mytable WHERE date='$date'";
        $re = mysql_query($q);
        $num = mysql_num_rows($re);
        $num--;
        $q = "DROP FROM mytable WHERE date='$date' LIMIT $num";
        mysql_query($q);
    }
    

    Should do the trick. More specifically, when creating your $date value, you have to provide PHP with a time to use. date() defaults to using the current time, but you can provide it with a custom time as the second argument.

    I suggest you take a look at the strtotime() manual at php.net as well (To translate times in your db to timestamps that can be used with date() ).

    EDIT: The Answer above has been edited to remove all duplicate entries.

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

Sidebar

Related Questions

I have this table structure and would like to map it using Fluent Hibernate
i have a table (tbl_world) which look like this id | first_name | last_name
I have a table like this: someid somestring 1 Hello 1 World 1 Blah
Any help here would be greatly appreciated. I have this table hospital Nurse |
I have a lot of rows to delete in a table, and using ADO.NET
I have a view like this: CREATE VIEW MyView AS SELECT Column FROM Table
The scenarios is like this: We have some SQL table. We are performing an
I have this log table in MySQL with columns ActionName and SourceName. The same
I have this table in an Oracle DB which has a primary key defined
I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) NOT

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.