select goods_id ,goods_name from ecs_goods where goods_id=1 union all select goods_id ,goods_name from ecs_goods where goods_id=4232222 union all select goods_id ,goods_name from ecs_goods where goods_id=34 union all select goods_id ,goods_name from ecs_goods where goods_id=4999999 union all select goods_id ,goods_name from ecs_goods where goods_id=3222
select goods_id ,goods_name from ecs_goods where goods_id=1 union all select goods_id ,goods_name from ecs_goods where goods_id=4232222 union all select goods_id ,goods_name from ecs_goods where goods_id=34 union all select goods_id ,goods_name from ecs_goods where goods_id=4999999 union all select goods_id ,goods_name from ecs_goods where goods_id=3222
用union all效率高。还是用循环效率高 ? 比如$ar = array(1,4232222,34,4999999,3222)foreach($ar as $k){ select goods_id ,goods_name from ecs_goods where goods_id="$k" }
union all
select goods_id ,goods_name from ecs_goods where goods_id=4232222
union all
select goods_id ,goods_name from ecs_goods where goods_id=34
union all
select goods_id ,goods_name from ecs_goods where goods_id=4999999
union all
select goods_id ,goods_name from ecs_goods where goods_id=3222
union all
select goods_id ,goods_name from ecs_goods where goods_id=4232222
union all
select goods_id ,goods_name from ecs_goods where goods_id=34
union all
select goods_id ,goods_name from ecs_goods where goods_id=4999999
union all
select goods_id ,goods_name from ecs_goods where goods_id=3222
比如$ar = array(1,4232222,34,4999999,3222)foreach($ar as $k){
select goods_id ,goods_name from ecs_goods where goods_id="$k"
}
如果只是四条记录,则直接用IN,IN的效率并不差。
如果 select goods_id ,goods_name from ecs_goods where goods_id in ( 这里有50个值呢)?这个时候用循环好?
还是union好
还是for循环好。 ?