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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:38:40+00:00 2026-05-25T21:38:40+00:00

Problem SOLVED! Update: Not quite right what I need, lets do example on simple

  • 0

Problem SOLVED!

Update:

Not quite right what I need, lets do example on simple table with fields ID,NAME,COVER

I have got 100 entries with 100 names, some of the names are duplicated, but I want only update first one from duplicates.


Trying to update all the 1st rows from all the duplicates in database, really hard to do it, any idea how I can make it? Below is the code I am trying to rebuild, but this code replace every 1st one with the last one for all the duplicates.

Schema, how I want it work below

ID NAME COVER
1  Max   1
2  Max   0
3  Andy  1
4  Andy  0
5  Andy  0

UPDATE table t
  JOIN (
    SELECT MinID, b.Name LatestName
    FROM table b
    JOIN (
      SELECT MIN(ID) MinID, MAX(ID) MaxID
      FROM table
      GROUP BY tag
      HAVING COUNT(*) > 1
    ) g ON b.ID = g.MaxID
  ) rs ON t.ID = rs.MinID
SET t.Name = LatestName;
  • 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-25T21:38:41+00:00Added an answer on May 25, 2026 at 9:38 pm

    It’s not clear at all what you want. Perhaps this:

    UPDATE table AS t
      JOIN 
        ( SELECT MIN(ID) MinID
          FROM table
          GROUP BY Name
          HAVING COUNT(*) > 1
        ) AS m 
        ON t.ID = m.MinID
    SET t.Cover = 1 ;
    

    For this (and future) question, keep in mind, when you write a question:

    1. a description of your problem, as clear as possible    --- you have that
    2. data you have now (a few rows of the tables)           --- ok, nice
    3. the code you have tried                 --- yeah, but better use same names
                                               --- as the data and description above
    4. the error you get (if you get an error)      --- doesn't apply here
    5. the result you want (the rows after the update in your case)
                                           --- so we know what you mean in case we 
                                           --- haven't understood from all the rest 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Update: Problem solved! See bottom of the post] I need to allow python developers
The problem is not solved although I accepted one answer. Problem: Vim updates very
UPDATE: First problem solved, second one described at the bottom of this post. UPDATE2:
Update II Problem Solved but Why? This has been the biggest headache ever. My
Problem solved: Thanks guys, see my answer below. I have a website running in
Problem solved, see below Question I'm working in Flex Builder 3 and I have
EDIT: Update - scroll down EDIT 2: Update - problem solved Some background information:
We are using trac. In our setup we have a problem that is solved
Problem I have timestamped data, which I need to search based on the timestamp
PROBLEM SOLVED! STUPID TYPO IN MY CODE! That's my method of my UIScrollView delegate:

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.