Manixat Posted April 2, 2013 Share Posted April 2, 2013 (edited) 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? Edited April 2, 2013 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/276422-one-big-query-or-a-thousand-small-ones/ Share on other sites More sharing options...
Solution awjudd Posted April 2, 2013 Solution Share Posted April 2, 2013 (edited) 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 Edited April 2, 2013 by awjudd Quote 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! Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.