How to generate column names dynamically from row values

In this post you will learn how to get row values of two tables in separate columns using MySql queries. This query will generate column names dynamically from row values. This post includes the queries for creating database, creating tables, get join data of two tables and finally getting column names dynamically from row values with simple example.

Follow below steps

Step 1. Query to Create Database

Step 2. Query to Create/Insert Tables

Step 3. Query to get all rows

Step 4. Query to get single row with dynamic columns

Note : We are using three rows for example you will get these rows values in single row with their values in separate columns.

Just follow the steps of the tutorial and you will get the value you want which you can modify according to your need.

  • Victor Lopez

    Hello, in your sample you created new fields val1, val2 and val3 with the content of “fieldvalue”, I need something similar but name the new fields with the content: 1,2,3 perhaps with a character before: C_1, C_2, C_3 and the content with zeros; Do you think this is possible?