Merging multiple rows into one row and multiple columns on mysql

后端 未结 3 1096
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 07:45

I am working in MYSQL and need to extract user data to be pulled into a view. I will be using the data in an email client, so I cannot do this in the app layer.

The

3条回答
  •  时光取名叫无心
    2020-12-30 07:57

    If these are the only columns you are concerned with, this will work for you:

    SELECT um.user_id
       , fn.meta_data AS first_name
       , ln.meta_data AS last_name
       , e.meta_data AS email
    FROM wp_userMeta AS um
    LEFT JOIN wp_user_Meta AS fn ON um.user_id = fn.user_id
       AND fn.meta_key = 'first_name'
    LEFT JOIN wp_user_Meta AS ln ON um.user_id = ln.user_id
       AND ln.meta_key = 'last_name'
    LEFT JOIN wp_user_Meta AS e ON um.user_id = e.user_id
       AND e.meta_key = 'email'
    

提交回复
热议问题