SQL 使用inner join联合查询两张表

使用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

猜你喜欢

转载自www.cnblogs.com/AliceYing/p/11821358.html