MySQL single statement to merge two tables

前端 未结 5 891
傲寒
傲寒 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:44

    Another simple way to fetch data using subquery.

    SELECT hash, (select value from USER_FIELD where key = 'firstname' and user_id=6 ) as firstname, (select value from USER_FIELD where key = 'lastname' and user_id=6 ) as lastname FROM `USER` where ID = 6 
    

    but it is not good way. You will have to compromise with performance, if database goes large. You should use another design pattern.

提交回复
热议问题