2
\$\begingroup\$

with below query i'm getting the results that i want but it's quite slow taking nearly 0.2 seconds (on an i5 machine). Is there a more optimized way to get the same results.

Basically this query fetches the last 20 rows in the table and shows only one row per yzr.name and orders by yzr.favorite_count

SELECT      gzt.name AS gazete,
            yz.*,
            yzr.name, 
            yzr.gazete_id, 
            yzr.yazar_image_link, 
            yzr.favorite_count, 
            DATE_FORMAT(tarih,'%d.%m.%Y') As formatted_tarih 

FROM        yazar AS yzr 

INNER JOIN  yazi   yz  ON yzr.id=yz.yazar_id 
INNER JOIN  gazete gzt ON yzr.gazete_id = gzt.id 

GROUP By    yzr.name
ORDER BY    yzr.favorite_count DESC 

LIMIT 20 OFFSET 0 
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

As you have no range specific functions applied in the SELECT clause I don't understand why you need the GROUP BY clause.

The expression is way to simple to be optimized (its hard to see how you can go wrong).

For any optimization advice you will need to provide the table definitions and an explanation of the Normal Form the data has been decomposed to. Optimization of SQL queries usually lies in the table structure and not decomposing the data to full actualized third Normal Form.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.