日期:2014-05-18  浏览次数:20380 次

在sql里面用in的效率很地下 那么用什么来代替呢?
一个user表
一个product表
id
userid
product_name


如果想找到username= 'test '   的所有product的话   用
select   *   from   product   where   userid   in   (select   id   from   user   where   username= 'test ')
这样的语句,可当数据量大的时候效率非常的底下

那怎么样提高效率呢?




------解决方案--------------------
select * from product inner join user on product.userid = user.id and user.username = 'test '
------解决方案--------------------
select *
from product a,user b
where a.userid = b.id and b.username= 'test '