1

How to get the following output in mysql table?

source table:

   id  values
    1    a
    2    b
    3    c
    4    d
    5    e

Result:

id  values
1    a
2    ab
3    abc
4    abcd
5    abcde
7
  • 2
    did you try anything... Commented Jun 6, 2014 at 6:40
  • And, what is your idea for achieving this? Commented Jun 6, 2014 at 6:40
  • Codeeeeeeeee.... We want code or anything you tried for helping you Commented Jun 6, 2014 at 6:41
  • What you try? Give code which you try to achieve this? have you any try? Commented Jun 6, 2014 at 6:41
  • I could not get exact code.. Commented Jun 6, 2014 at 6:54

1 Answer 1

1
SELECT  a.id, (@inc := concat(@inc, a.name)) AS Name
FROM  mytable a, (SELECT @inc:= '') c ORDER BY a.id ASC

SQLFIDDLE DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

+1 although you should add order by id since you can't rely on an order unless you specify it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.