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

  • SEARCH
  • Home
  • 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 7510345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:12:19+00:00 2026-05-29T23:12:19+00:00

I have a table in my database to store user data. I found a

  • 0

I have a table in my database to store user data. I found a defect in the code that adds data to this table database where if a network timeout occurs, the code updated the next user’s data with the previous user’s data. I’ve addressed this defect but I need to clean the database. I’ve added a flag to indicate the rows that need to be ignored and my goal is to mark these flags accordingly for duplicates. In some cases, though, duplicate values may actually be legitimate so I am more interested in finding several user’s with the same data (i.e, u> 2).

Here’s an example (tablename = Data):

id—- user_id—-data1—-data2—-data3—-datetime———–flag

1—–usr1——–3———- 2———2———2012-02-16..—–0

2—–usr2——–3———- 2———2———2012-02-16..—–0

3—–usr3——–3———- 2———2———2012-02-16..—–0

In this case, I’d like to mark the 1 and 2 id flags as 1 (to indicate ignore). Since we know usr1 was the original datapoint (assuming the oldest dates are earlier in the list).

At this point there are so many entries in the table that I’m not sure the best way to identify the users that have duplicate entries.

I’m looking for a mysql command to identify the problem data first and then I’ll be able to mark the entries. Could someone guide me in the right direction?

  • 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-29T23:12:20+00:00Added an answer on May 29, 2026 at 11:12 pm

    Well, first select duplicate data with their min user id:

    CREATE TEMPORARY TABLE duplicates
      SELECT MIN(user_id), data1,data2,data3
      FROM data
      GROUP BY data1,data2,data3
      HAVING COUNT(*) > 1                       -- at least two rows
         AND COUNT(*) = COUNT(DISTINCT user_id) -- all user_ids must be different
         AND TIMESTAMPDIFF( MINUTE, MIN(`datetime`), MAX(`datetime`)) <= 45;
    

    (I’m not sure, if I used TIMESTAMPDIFF properly.)
    Now we can update the flag in those rows where user_id is different:

    UPDATE     duplicate
    INNER JOIN data      ON data.data1 = duplicate.data1
                        AND data.data2 = duplicate.data2
                        AND data.data3 = duplicate.data3
                        AND data.user_id != duplicate.user_id
    SET data.flag = 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some user-specific data that I need to store in SharePoint and make
My iphone app uses a SQLite database to store data. I have a table
Ok I have a table in my SQL Server database that stores comments. My
I'm overthinking this. I have colors stored in a database table, and I want
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have a mysql database table to store country name and currency symbol -
I store user data in a MSSQL table called Users. What I want to
I have a table in my database which stores a tree structure. Here are
I have a database table A which stores records, A has a primary key
I have a database table called Posts which stores all the information regarding an

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.