SELECT DISTINCT, tPost.country_code, tPost.category_id, tPost.post_type_id, tPost.title, tPost.price, tPost.city_id, tPost.featured, tPost.created_at, tPost.reviewed, tPost.verified_email, tPost.verified_phone,, tPost.contactseller, tPost.state, (tPost.price * 1) AS calculatedPrice, tPayment.package_id, tPackage.lft, (ST_Distance_Sphere(POINT(tPost.lon,, POINT(:longitude, :latitude)) / 1000) AS distance FROM posts AS tPost INNER JOIN categories AS tCategory ON AND LEFT JOIN categories AS tParent ON AND LEFT JOIN categories AS lCategory ON AND lCategory.translation_lang = :translationLang LEFT JOIN categories AS lParent ON AND lParent.translation_lang = :translationLang LEFT JOIN (SELECT MAX(id) lid, post_id FROM payments WHERE active=1 GROUP BY post_id) latestPayment ON AND tPost.featured=1 LEFT JOIN payments AS tPayment ON LEFT JOIN packages AS tPackage ON WHERE tPost.country_code = :countryCode AND (tPost.verified_email = 1 AND tPost.verified_phone = 1) AND tPost.archived != 1 AND tPost.deleted_at IS NULL AND tPost.reviewed = 1 AND tPost.category_id = :subCatId GROUP BY, tPayment.package_id, tPackage.lft HAVING distance <= 50 ORDER BY tPackage.lft DESC, tPost.created_at DESC, distance ASC