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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:13:31+00:00 2026-06-12T20:13:31+00:00

My sql query so far has a few joins on tables and the final

  • 0

My sql query so far has a few joins on tables and the final output looks like this:

FLAG        id      name
----        ---     ----
OK          21      ken
OK          34      mon
OK          51      jil
OK          51      jil
OK          71      jil
OK          80      ron
OK          91      ron

Now I want the FLAGs of duplicate names be shown as ‘dup’ of the lowest id:

FLAG        id      name
----        ---     ----
OK          21      ken
OK          34      mon
OK          51      jil
dup_51      51      jil
dup_51      71      jil
OK          80      ron
dup_80      91      ron

I can do it by using shell/perl script on the records stored in a file, but need to know if it can be possible by manipulating my SQL query.. Thanks for your time and help.

  • 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-12T20:13:32+00:00Added an answer on June 12, 2026 at 8:13 pm

    I would suggest a subquery that tracks duplicate entries on name and returns the minimum id for each duplicate. I’ll asume your table is named tbl:

    select name, min(id) as dupId
    from tbl
    group by name
    having count(name) > 1
    

    Now you can join this with your original table:

    select 
        tbl.*, if(not isnull(dupId), 'Ok', concat('dup_', dupId)) as flag2
    from 
        tbl
        left join (
            select name, min(id) as dupId
            from tbl
            group by name
            having count(name) > 1) as a on tbl.name = a.name
    

    This is a way to do it. Hope it helps you.

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

Sidebar

Related Questions

My SQL query looks like this... sekect * FROM mail_headers a LEFT JOIN mail_headers_body
i have this sql query select * from table where name like ? but
I have a SQL query running using something like this: PreparedStatement pstmt = dbConn.prepareStatement(sqlQuery);
I recently upgraded to Oracle Sql Developer 2.1 It's far better, but the query
SQL query which select the record from three tables and there is no relation
Below SQL query works when the spaces in the role name are replaced by
Original SQL query is this; SELECT id,post_title,post_date FROM wp_posts where id='1' When I retrieve
this is by far my toughest question yet and I'm hoping someone has stumbled
I have a rather large SQL query which the majority of which has come
I might have a problem with my SQL query. In this query I'm combining

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.