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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:02:08+00:00 2026-05-17T22:02:08+00:00

i have a mysql result set like bellow id name ——————— 1 abc 1

  • 0

i have a mysql result set like bellow

id        name
---------------------
1         abc
1         abc
2         xyz
2         xyz
3         pqr

now i need to modify the result set so that it would be like as follows:

id        name
---------------------
1         abc-1
1         abc-2
2         xyz-1
2         xyz-2
3         pqr

the summarization is i need to numbering the name column from result set and the numbering will only apply on the rows which have more than one value in the result set.

so what will be the MySQL SELECT Query?

  • 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-17T22:02:09+00:00Added an answer on May 17, 2026 at 10:02 pm

    this might work but there’s probably a better way that i can’t think of right now

    set @i = 0;
    
    select
     f.id,
     @i:=@i+1 as i,
     case 
      when c.counter <= 1 then f.name 
      else concat(f.name,'-',(@i % c.counter) +1)
     end as name
    from
     foo f
    join (select id, count(*) as counter from foo group by id) c on c.id = f.id
    order by
     f.id,name;
    

    EDIT: as stated in comments above, better to do this at the app level vs. db

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

Sidebar

Related Questions

I have a table x that's like the one bellow: id | name |
I have a MySQL result set $fields_num = mysql_num_fields($result); I would like to assign
I have a MySQL query that returns a result with a single column of
I have a MySQL database that is exhibiting behavior I would like to understand
I have a MySQL database table that stores the URLs of photos. I need
I have an set numeric ranges that I would like to optimize. Here's a
I have a MySQL database of keywords that are presently mixed-case. However, I want
I have a set of data that's organized hierarchically that should be able to
I have three tables I'd like to join in a way that produces all
I have a MySQL table laid out like this: ID | Artist | Title

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.