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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:46:52+00:00 2026-05-11T17:46:52+00:00

I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where

  • 0

I have the following table structure (in MySQL):

DocID, Code, IsDup, DopOf

, where DocID is Unique.

Values are like :

1,AAAA,nul,nul
2,AAAA,nul,nul
3,AAAA,nul,nul
4,BBBB,nul,nul
5,CCCC,nul,nul
6,CCCC,nul,nul

What I want is to write a procedure which can update the table and give the desired result as:

1,AAAA,0,0
2,AAAA,1,1
3,AAAA,1,1
4,BBBB,0,0
5,CCCC,0,0
6,CCCC,1,5

IsDup shows whether the Doc is duplicate or not on the basis of Code,
and DupOf indicates the original DocId.

Can anybody help me? I’m trying to implement the logic, but I’m stuck.

Your help would be highly appreciated.

Thanks.

  • 1 1 Answer
  • 1 View
  • 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-11T17:46:52+00:00Added an answer on May 11, 2026 at 5:46 pm
    UPDATE  table t
    JOIN    (
            SELECT  code, MIN(docId) AS firstdoc
            FROM    table
            GROUP BY
                    code
            ) q
    ON      t.code = q.code
    SET     t.isDup = NOT (t.docId = q.firstdoc), 
            t.dupOf = CASE WHEH t.docId = q.firstdoc THEN 0 ELSE q.firstDoc END
    

    If your table is MyISAM, you should have an index on (code, docId).

    If your table is InnoDB and docId is a PRIMARY KEY, you should have an index on (code).

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

Sidebar

Related Questions

I have a MySQL table with a structure like the following: I'm looking for
In MySQL, is it bad to have a table structure like the following... Table
I have the following MySQL table structure: num field company phone website 1 Gas
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have a MySQL database with the following table structure: TransactionType : Transaction_Amount, Transaction_ID,
I have following table structure in Mysql DB Table: Mytable -------------------------------- | uid |
I have the following MySQL structure (minimized a lot): CREATE TABLE `site_movies` ( `id`
I have the following table structure in my db (MySQL): id group_id item_id project_id
I have the following structure with a MySQL table: +----------------+----------------+----------+ | zipcode | city
I'm using PHP and MySQL and have the following table structure: date | name

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.