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

如何优化SQL语句?
C# code
select * from news where id=1 or id=2 or id=4 or id=18 or id=22 or id=33


上面这段SQL能否优化一下?

------解决方案--------------------
select * from news 
where id in(1,2,4,18,22,33)
------解决方案--------------------
id列上加索引

SQL code

select * from news where id=1 
union all
select * from news where id=2
union all
select * from news where id=4
union all
select * from news where id=18
union all
select * from news where id=22
union all
select * from news where id=33