$b_result2 = mysql_query("SELECT `userid`,`time` FROM `blog` WHERE `userid` IN($ids_list) GROUP BY `userid` ORDER BY `id` DESC");
while($b_array2 = mysql_fetch_assoc($b_result2)){
echo '<pre>';
print_r($b_array2);
echo '</pre>';
}
And this gives me what I want.
So the problem?
What I want to do is select the last blog entry for each id in $ids_list. Only ONE entry. Is this query selecting all the entries?
Say userid 10 has 8394 blogs. Is that all being fetched by this query?
When I throw a LIMIT 1 onto the end of the query it only returns one result... not one result per userid.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
It retrieves the last blog entry from each user in $ids_list, which is want I want.
But I fear that it's selecting ALL the blogs from each user and using more resources than it should. If I put LIMIT 1, it limites the whole query.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
If I had to guess, I would guess that that MySQL is retrieving all the rows, which it then groups. However, the query result you get back, won't have any extraneous information.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Have you timed your query to see how it is performing? You know, depending on your MySQL version, you may be able to run a subquery to this to try to optimize your data selection.