P
P
Puma Thailand2012-07-16 21:09:05
MySQL
Puma Thailand, 2012-07-16 21:09:05

How to make an index for a query with group by and order by?

The query itself is
SELECT Ad.id, Ad.title, Ad.description, Ad.posting_date, Ad.is_colored_listing, Ad.bg_color, Ad.fg_color, `Adi`.`image_name`, `Adc`.`category_alias`
FROM `daype_ads ` AS `Ad`
LEFT JOIN daype_categories AS `Adc` ON ( `Ad`.`category_id` = `Adc`.`id` )
LEFT JOIN daype_images AS `Adi` ON ( `Ad`.`id` = `Adi` .`ad_id` )
WHERE `city_id` =25
AND `Ad`.`category` =4
AND `Ad`.`status` =1
AND `category_id` =33
GROUP BY `Ad`.`id`
ORDER BY `posting_date ` DESC
LIMIT 20, 20

Executes seconds.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Edro, 2012-07-16
@Edro

AND `Ad`.`category` = 4
 ...
 AND `category_id` = 33

What does it mean?

A
Alexey Skahin, 2012-07-16
@pihel

Why grouping if there are no aggregating functions?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question