Jump to content

One big query or a thousand small ones?


Manixat

Recommended Posts

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

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! :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.