chewie07
10-09-2005, 05:08 PM
Hello, i need a little help with this query.
SELECT
n_news.id,
n_news.title,
n_news.date,
n_news.cat_id,
n_news.count,
n_cats.id as cat_id,
n_cats.nombre as cat_name,
n_cats.shortn as cat_shortn,
COUNT(DISTINCT n_comments.id) as com_num
FROM
n_news
LEFT JOIN
n_comments ON n_news.id = n_comments.news_id
LEFT JOIN
n_cats ON n_news.cat_id = n_cats.id
WHERE
n_news.date > 1126255152
GROUP BY
n_news.id
ORDER BY
n_news.date
DESC
LIMIT 20
When explaining it:
http://fusionnintendo.net/files/chewie/explainsql.jpg
So, as you see i am using indexes, but in the first table (the one i call with the where clause) it is still searching in all the rows in the table (2007). what i want is to reduce that number only to the number of rows needed (exactly as i did with the left join statements).
Any idea?
Regards.
SELECT
n_news.id,
n_news.title,
n_news.date,
n_news.cat_id,
n_news.count,
n_cats.id as cat_id,
n_cats.nombre as cat_name,
n_cats.shortn as cat_shortn,
COUNT(DISTINCT n_comments.id) as com_num
FROM
n_news
LEFT JOIN
n_comments ON n_news.id = n_comments.news_id
LEFT JOIN
n_cats ON n_news.cat_id = n_cats.id
WHERE
n_news.date > 1126255152
GROUP BY
n_news.id
ORDER BY
n_news.date
DESC
LIMIT 20
When explaining it:
http://fusionnintendo.net/files/chewie/explainsql.jpg
So, as you see i am using indexes, but in the first table (the one i call with the where clause) it is still searching in all the rows in the table (2007). what i want is to reduce that number only to the number of rows needed (exactly as i did with the left join statements).
Any idea?
Regards.