Tema: Re: ilgas sql
Autorius: Tomas
Data: 2009-02-04 15:31:45
reiktu gal komentaru skaiciu saugoti prie straipsnio, nereiktu tada joining ir skaiciuot

tobias wrote:
> kaip optimizuoti mysql query - jei jis vykdomas 40 sekundziu!
> jokiu fokusu nedarau
> paselektinu straipnio id, headline,
> is komentaru lenteles suskaiciuoju komentaru skaiciu
> 
> aciu uz komentarus
> 
> 
>      SELECT articles.id,
>      articles.title,
>      articles.date,
>      DATE_FORMAT(date,'%m/%d, %Y') as ArticleDate,
>      articles.selected_foto,
>      articles.foto_1,
>      articles.foto_source,
>      REPLACE(articles.source, ',', ' ') as source,
>      LEFT(articles.article,350) as article_intro,
>      COUNT(comments.id) as artComments
>      FROM articles
>      LEFT JOIN comments ON articles.id = comments.object_id
>      WHERE articles.active  = '1'
>      AND articles.category  = '21'
>      GROUP BY articles.id
>      ORDER BY articles.id
>      DESC
>      LIMIT 5 
> 
>