Select distinct … inner join vs. select … where id in (…)

前端 未结 3 1291
甜味超标
甜味超标 2021-01-19 12:58

I\'m trying to create a subset of a table (as a materialized view), defined as those records which have a matching record in another materialized view.

For example,

3条回答
  •  离开以前
    2021-01-19 13:50

    Try this

    select * from Users u
    where exists 
       ( select user_id 
         from Log_mview l
         where l.user_id = u.user_id )
    /
    

    If the sub-query returns a large number of rows WHERE EXISTS can be substantially faster than WHERE ... IN.

提交回复
热议问题