Manixat Posted April 2, 2013 Share Posted April 2, 2013 Hello again freaks, I have a dilemma here that I thought I would ask for a professional opinion. $mysqli->query("SELECT * FROM `table` WHERE `id`='$id1' OR `id`='$id2' OR `id`='$id3' ... OR `id`= '$id3001' OR `id`='$id3002'"); or $mysqli->query("SELECT * FROM `table` WHERE `id`='$id1'"); $mysqli->query("SELECT * FROM `table` WHERE `id`='$id2'"); $mysqli->query("SELECT * FROM `table` WHERE `id`='$id3'"); ... $mysqli->query("SELECT * FROM `table` WHERE `id`='$id3001'"); $mysqli->query("SELECT * FROM `table` WHERE `id`='$id3002'"); which is the better way to go? Link to comment https://forums.phpfreaks.com/topic/276422-one-big-query-or-a-thousand-small-ones/ Share on other sites More sharing options...
awjudd Posted April 2, 2013 Share Posted April 2, 2013 One big query. It can hit the index once and do it's business. Since you are doing ORs, you may want to consider switching it to an IN clause. SELECT * FROM `table` WHERE `id` IN ( $id1, $id2 ) ~awjudd Link to comment https://forums.phpfreaks.com/topic/276422-one-big-query-or-a-thousand-small-ones/#findComment-1422432 Share on other sites More sharing options...
Manixat Posted April 2, 2013 Author Share Posted April 2, 2013 One big query. It can hit the index once and do it's business. Since you are doing ORs, you may want to consider switching it to an IN clause. SELECT * FROM `table` WHERE `id` IN ( $id1, $id2 ) ~awjudd Excellent, thank you for this reply! Link to comment https://forums.phpfreaks.com/topic/276422-one-big-query-or-a-thousand-small-ones/#findComment-1422433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.