SQLはinner joinを使って共同で二つの表を調べます.

1678 ワード

inner joinを使って共同で二つの表を調べて、各表を調べる時には単独のwhere条件を追加できます.
select
    tabel1.id,
    tabel1.name,
    tabel2.address,
from
    (
        select
            id,
            name,
            age
        from
            id_name_age_table
        where
            age < 50
    ) as tabel1
    inner join (
        select
            id,
            address,
            income
        from
            id_address_income_table
        where
            income > 10000
    ) as tabel2 on tabel1.id = tabel2.id