Tema: Re: ilgas sql
Autorius: Tadas Kvedaras
Data: 2009-02-06 08:34:51
Sveikas,

Debug'ink. Pagal mane, tai stabdo tas LEFT JOIN (daug komentar??).

Kodl taip skaiiuoji komentarus? Nafik eit  "kair" ;-)

SELECT articles.id
               (SELECT count(comments.id) FROM comments WHERE 
comments.object_id = articles.id) as artComments
FROM articles
WHERE articles.active  = '1' AND articles.category  = '21'


Gal greiiau?

--
Tadas K.


"tobias" <oracullusTRINAM@yahoo.com> wrote in message 
news:gmc593$9aa$1@trimpas.omnitel.net...
> 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
>