Most efficient way of fetching 1,000 records from MySQL ?

From: Date: Mon, 25 Oct 2004 08:15:55 +0000
Subject: Most efficient way of fetching 1,000 records from MySQL ?
Groups: php.general 
Request: Send a blank email to php-general+get-200226@lists.php.net to get a copy of this message
Hello, In my script I have generated an array of 1,000 userIDs for example. Now for I need to fetch each user's record and I am wondering what is the best way to go about it: 1) 1000 sql queries // code is sort of pseudo for clarity foreach($users as $userID) { $user = sql("select * from users where userID = '$userID'"); // bla bla } 2) 1 query $users = sql("select * from users where userID='1' or userID='2' or userID='5' or userID='10'"); I imagine the 2nd one would be a bit of a nightmare for MySQL to parse, if it gets too long? Or am I missing a more efficient 3rd / 4th option? Many thanks in advance for your help. Steve McGill

« previous php.general (#200226) next »