将子查询转换为join语句

时间:2013-11-20 07:19:28

标签: sql oracle select join

我有这个选择声明:

select * 
from users u  
where u.user_id in (
    select distinct user_id 
    from user_filial 
    where filial_id in (
        select filial_id 
        from user_filial 
        where user_id = 101
    )
);

我需要将其转换为与Joins的声明。

2 个答案:

答案 0 :(得分:1)

SELECT U.* 
FROM
    users U
    INNER JOIN user_filial UF ON UF.filial_id = U.filial_id
WHERE U.user_id = 101

答案 1 :(得分:0)

这是使用连接表示的等效查询:

select distinct u.*
from user_filial uf
join user_filial uf2 on uf2.filial_id = uf.filial_id
join users u on u.user_id = uf2.user_id
where uf.user_id = 101