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 
Loki Astari
97.6k5 gold badges126 silver badges341 bronze badges
asked Apr 14, 2013 at 10:06
\$\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.

answered Apr 14, 2013 at 15:02
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.