1

I want to combine two or more rows which have the same name and put their values in two separate column. The problem can be clearer with the following images: enter image description here

My expected output is:

enter image description here

You can check the fiddle here: fiddle

What I have tried so far is with the MySQL code:

Select subjects, mark_score, activity 
   FROM(
      SELECT subjects,  mark_score, 
      (SELECT regd, subjects, mark_score 
       FROM exo_i WHERE entry='7' and regd='19') as activity 
       FROM exo_i WHERE regd='19' GROUP BY subjects)t
2
  • I'm assuming you want to display "marks" for the FA1 entry and "activity" for the SA1 activity. Do I understand the requirement correctly? Commented Jul 9, 2015 at 5:11
  • @Mureinik, Yes you are right. That's what I want. Commented Jul 9, 2015 at 5:13

1 Answer 1

1

As discussed in the comment, the requirement is to display "marks" for the "FA1" entry and "activity" for the "SA1" activity. Assuming there can't be multiple rows with these values (i.e., the combination of regd, subjectsa and activity is unique), you could have a subquery for each of these activities, and join them:

SELECT a.regd, a.subjects, a.marks, b.activity
FROM   (SELECT regd, subjects, marks
        FROM   mytable
        WHERE  entry = 'FA1') a
JOIN   (SELECT regd, subjects, marks AS activity
        FROM   mytable
        WHERE  entry = 'SA1') b ON a.regd = b.regd AND a.subjects = b.subjects
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.