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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:21:30+00:00 2026-06-12T01:21:30+00:00

I have this records in MySQL below RecID | Description | Date | Hits

  • 0

I have this records in MySQL below

RecID | Description | Date | Hits | IsPublished 
1; "Test"; 04/10/2012; 45; True
2; "Test 1"; 04/10/2012; 37; True
3; "Test 2"; 05/10/2012; 12; True
4; "Test 3"; 05/10/2012; 13; True
5; "Test 4"; 07/10/2012; 14; True
6; "Test 5"; 07/10/2012; 25; True
7; "Test 4"; 08/10/2012; 23; True
8; "Test 5"; 08/10/2012; 35; True
9; "Test 9"; 12/10/2012; 7; True

Would like to achieve the following

9; "Test 9"; 12/10/2012; 7; True 
8; "Test 5"; 08/10/2012; 35; True
4; "Test 3"; 05/10/2012; 13; True

Basically, the first rule is to group the date which is 08/10/2012, 07/10/2012 and 05/10/2012 and 04/10/2012. Use this 08/10/2012 as a starting point. Then remove any dates that is close to each other (min 1 day).

BTW … this is an Australian date (DD/MM/YYYY). Therefore, the result is 08/10/2012, 05/10/2012. Out of these 2 “valid” days and then pick the record that has more hits on that day. Then set the others as IsPublished = false.

Any ideas to do this in MySQL?

  • 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-12T01:21:31+00:00Added an answer on June 12, 2026 at 1:21 am

    First find the dates that have no other rows with a day larger by 1:

        SELECT DISTINCT t1.Date
        FROM table_name t1
        LEFT JOIN table_name t2
          ON DATE_ADD(t1.Date, INTERVAL 1 DAY) = t2.Date
        WHERE t2.RecId IS NULL
    

    Then find the max hits for these dates:

      SELECT Date, MAX(Hits) as maxHits
      FROM table_name
      WHERE Date IN (
        SELECT DISTINCT t1.Date
        FROM table_name t1
        LEFT JOIN table_name t2
          ON DATE_ADD(t1.Date, INTERVAL 1 DAY) = t2.Date
        WHERE t2.RecId IS NULL )
      GROUP BY Date
    

    Finally, update all rows that don’t match these dates and maxHits:

    UPDATE table_name toUpdate, (    
      SELECT Date, MAX(Hits) as maxHits
      FROM table_name
      WHERE Date IN (
        SELECT DISTINCT t1.Date
        FROM table_name t1
        LEFT JOIN table_name t2
          ON DATE_ADD(t1.Date, INTERVAL 1 DAY) = t2.Date
        WHERE t2.RecId IS NULL )
      GROUP BY Date) source
    SET toUpdate.IsPublished = false
    WHERE toUpdate.Date != source.Date OR toUpdate.Hits != source.maxHits
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have stored 6 records in mysql db,when i use this code each of
I have this table Test as Id, SomeValue, SomeText contains about a mill records,
I have some records like this: ID Personel_Code Time --- ------------- ------ 1 0011
I have a variable like Doctor and Surgical I take this value from Mysql
I would like to pass a MySQL Datetime value like below in a site
I have a MySQL database that is exhibiting behavior I would like to understand
I have this weird problem in java when trying to fetch records from MYSql
So I have this JS form that creates a new record ( MySQL ,
I have this (I'm only showing three records, there are many, many more) Array
I have this query that, due to the number of records, is taking several

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.