0

My database looks like this:

enter image description here

As you can see there's the "submission_id" column which is the same for each row containing the related data in the "field_value" column. And here is my problem, I'm stuck here. I want the values of "field_value" column - which are related to each other based on the submission id - to be in separate columns like on this picture: enter image description here

How can I do that? I tried but I'm a potato to MySQL and PHP.

Thank you for all the helps!

Shadow
  • 33,525
  • 10
  • 51
  • 64
peter
  • 23
  • 5
  • The current DB seems like it was designed with the intention for infinite data insertion possibilities. The proposed solution would be finite. Is `sub field value` a known list or plain text? Alternatively creating a view might be a better approach. https://dev.mysql.com/doc/refman/8.0/en/views.html Then you won't need to muck up the name data, it will be hard to decipher firstname/lastname once merged. – user3783243 Jan 14 '22 at 11:53
  • hi, you have to get the data with JOIN (https://www.w3schools.com/mysql/mysql_join.asp) – Arkadiusz G. Jan 14 '22 at 11:54
  • @ArkadiuszG. The data is all in one table currently, just different rows. e.g. 503, 504, and 505 need to be combined to give the result in the image. – user3783243 Jan 14 '22 at 11:55
  • This is a pivot transformation (aka rows to columns), with an extra twist that you want the names column to be concatenated from two elements (columns). – Shadow Jan 14 '22 at 11:57
  • Well, I don't have to concatenate the names, there may be separate columns for the first name and the last name just so as not to complicate it – peter Jan 14 '22 at 12:35

0 Answers0