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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:05:51+00:00 2026-05-14T22:05:51+00:00

I’m trying to update a table to remove all but the first instance of

  • 0

I’m trying to update a table to remove all but the first instance of a group. Basically, I have a table with vehicle data related to an insurance policy. Each policy should only have one power_unit. Everything else should be a towed unit. Unfortunately, a bug has been duplicating power units, and now I need to clean this up. There are ~10k records in the database, and ~4k of them have doubled up power units.

The important bits of my table (call it test1 for now) are:

+------------+---------+------+-----+---------+----------------+
| Field      | Type    | Null | Key | Default | Extra          |
+------------+---------+------+-----+---------+----------------+
| id         | int(10) | NO   | PRI | NULL    | auto_increment | 
| policy_id  | int(10) | NO   |     | NULL    |                | 
| power_unit | int(1)  | NO   |     | 0       |                | 
+------------+---------+------+-----+---------+----------------+

And some sample data:

+----+-----------+------------+
| id | policy_id | power_unit |
+----+-----------+------------+
|  1 |         1 |          1 | 
|  2 |         1 |          1 | 
|  3 |         1 |          1 | 
|  4 |         2 |          1 | 
|  5 |         2 |          1 | 
|  6 |         2 |          1 | 
|  7 |         4 |          1 | 
|  8 |         4 |          1 | 
|  9 |         4 |          1 | 
| 10 |         5 |          1 | 
| 11 |         5 |          1 | 
| 12 |         6 |          1 | 
+----+-----------+------------+

Basically I’d like to end up where policy_id 1 has only one power_unit=1. Same for policy_id 2, 3, 4, etc. For policy_id 6, nothing should change (there is only one entry, and it is a power_unit already).

I don’t know if this is possible, but it was an intriguing problem for me, so I thought you guys might find it the same.

Update:
I don’t want to DELETE the rows, just UPDATE them to have power_unit=0.

  • 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-14T22:05:52+00:00Added an answer on May 14, 2026 at 10:05 pm
    UPDATE  test1 t1,
            (
            SELECT  policy, MIN(ti.id) AS mid
            FROM    test1 ti
            GROUP BY
                    policy
            ) tm
    SET     power_unit = 0
    WHERE   t1.policy = tm.policy
            AND t1.id <> tm.mid;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I want to construct a data frame in an Rcpp function, but when I
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is

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.