Build HierarchyQUERY
SELECT l.*, t2.*
FROM cms_module_listings l
JOIN cms_module_listings_prodtohier h ON l.id = h.listing_id
JOIN (
SELECT tmp.hierarchy_id, h.name, max( listing_date ) AS max FROM ( SELECT h.hierarchy_id, l.id, l.listing_date from cms_module_listings l
JOIN cms_module_listings_prodtohier h ON l.id = h.listing_id WHERE status = ? AND l.listing_date < now() GROUP BY l.id ) tmp JOIN cms_module_listings_hierarchy h on tmp.hierarchy_id = h.id where upper(h.long_name) LIKE upper(?) group by tmp.hierarchy_id) t2 ON t2.hierarchy_id = h.hierarchy_id WHERE status = ? AND l.listing_date < now() group by l.id order by t2.max desc, t2.name asc, l.listing_date desc
SELECT tmp.hierarchy_id, h.name, max( listing_date ) AS max, h.extra1 as link, count(tmp.id) as count FROM ( SELECT h.hierarchy_id, l.id, l.listing_date from cms_module_listings l
JOIN cms_module_listings_prodtohier h ON l.id = h.listing_id WHERE status = ? AND l.listing_date < now() GROUP BY l.id ) tmp JOIN cms_module_listings_hierarchy h on tmp.hierarchy_id = h.id where upper(h.long_name) LIKE upper(?) group by tmp.hierarchy_id order by max desc, h.name asc
(published, %West Central Saskatchewan%, published)[0][5]
query1->0.009328
Heirarchy0.003426 -->0.125023
|
|
Regions of West Central Saskatchewan |