MySQL single statement to merge two tables

前端 未结 5 889
傲寒
傲寒 2021-01-24 04:01

I\'m sure this has been ask/answered already but I don\'t know how this kind of action is called and my SQL knowledge is limited.

I\'m searching for a single SQL statem

5条回答
  •  深忆病人
    2021-01-24 04:51

    Couple of Joins would do the trick.

    SELECT u.id, u.hash, uf_f.value AS firstname, uf_l.value AS lastname
    FROM user AS u 
    LEFT JOIN user_field AS uf_f ON uf_f.user_id = u.id AND uf_f.key = 'firstname'
    LEFT JOIN user_field AS uf_l ON uf_l.user_id = u.id AND uf_l.key = 'lastname'
    

提交回复
热议问题