Joining the result of two queries mysql

后端 未结 5 683
刺人心
刺人心 2021-01-20 16:06

Without actually giving all the details of my query: Is there a way of joing the results of two separate queries on different tables? for example if i had a table

re

5条回答
  •  没有蜡笔的小新
    2021-01-20 16:43

    Completing @Microgen's answer... Since you already have your two first select working as you want, you can keep those results in temporary tables:

    create temporary table tmp1 as ;
    alter table tmp1 add ;
    create temporary table tmp2 as ;
    alter table tmp2 add ;

    Then, you could apply a simple join to get your final result:

    select tmp1.id, tmp1.name, tmp1.address, tmp2.occupation
        from tmp1 inner join tmp2 using (id)
        order by tmp1.id;

    Another way to do it is to use VIEW, but since the indexing is not the best thing they have, I would avoid them, specially when your first two select are as complex.

提交回复
热议问题