Select * from UserInfo where uif_UserCode in (1,12) 用in在数据量大的时候效率不高,(1和12是传过来的值)除了这种方法还可以怎么写, 有人说用exists 到底要怎么写呢 ?列表值不多,用in性能也啥大不了的 其实列表项不多,in 和exists差别很小 如果要用exists必须存在另一个表中,uif_UserCode上建立索引。 Select * from UserInfo a where exists( select 1 from tempUserInfo b where a.uif_UserCode =b.uif_UserCode )
in 的话只要范围不大跟exists关键字差不多
要是范围大的话 可以考虑exists,可以建索引吧 Select * from UserInfo a where exists(select 1 from UserInfo where a.UserCode=UserCode) Select * from UserInfo where uif_UserCode in (1,12)
改成 Select * from UserInfo where uif_UserCode=1 or uif_UserCode=12
忘记哪个效率高了,呵呵,你试试
传的1和12不是固定的,有可能还会是3个数或者更多呢? 如果不用exists还有什么更好的方法吗? Select * from UserInfo where uif_UserCode=1 or uif_UserCode=12