Convert multiquery to a query using group by and so on
Posted
by
ffffff
on Stack Overflow
See other posts from Stack Overflow
or by ffffff
Published on 2011-01-06T03:50:54Z
Indexed on
2011/01/06
3:53 UTC
Read the original article
Hit count: 168
-schema
CREATE TABLE `ratings` (
`id` int(11) NOT NULL default '0',
`rating` int(11) NOT NULL default '1',
`rating_start` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) TYPE=MyISAM
-myprogram.php
foreach($ids as $id){
$sql = "SELECT rating FROM ratings WHERE id = '$id' AND rating_start >= NOW()";
$sql .= "ORDER BY rating_start DESC LIMIT 1;"
$ret = $db->execute($id);
}
Can I teke same date from a Query? by using id IN (".implode(",",$ids).") and GROUP BY id
© Stack Overflow or respective owner