• Resolved harrytiadi

    (@harrytiadi)


    How to display datas using sql query from multiple specific rows in one table sql into multiple columns? For example, insert red data into column1, insert blue data into column2, insert green data into column3, etc.

    I’ve used these code : SELECT um_value FROM wp_um_metadata WHERE um_key=’first_name’

    But the result I only got one column….

    Please help if someone has expert knowledge about MySQL here. Thanks for sharing it.

    Here the screenshot of example sql database : https://ibb.co/VtCYHj5

Viewing 1 replies (of 1 total)
  • Plugin Support Syed Numan

    (@annuman)

    Hello @harrytiadi,

    This is achievable with the correct MySql query. However, the query you wrote only retrieves the first name value from the column um_value, which will result in the value being returned in a single column.

    You should write the query like the below example.

    SELECT MAX(CASE WHEN meta_key = 'first_name' THEN meta_value END) AS column1,
           MAX(CASE WHEN meta_key = 'last_name' THEN meta_value END) AS column2, 
          MAX(CASE WHEN meta_key = 'email' THEN meta_value END) AS column3
    FROM wp_usermeta WHERE user_id = 2;

    Thank you

Viewing 1 replies (of 1 total)

The topic ‘How to query selected multiple rows into multiple colums’ is closed to new replies.