SELECT 
  cscart_companies.company_id, 
  cscart_companies.lang_code, 
  cscart_companies.email, 
  cscart_companies.company, 
  cscart_companies.timestamp, 
  cscart_companies.status, 
  cscart_company_descriptions.company_description, 
  cscart_vendor_plan_descriptions.plan, 
  cscart_seo_names.name as seo_name, 
  cscart_seo_names.path as seo_path, 
  AVG(
    cscart_discussion_rating.rating_value
  ) AS average_rating, 
  CONCAT(
    cscart_companies.company_id, 
    '_', 
    IF (
      cscart_discussion_rating.thread_id, 
      cscart_discussion_rating.thread_id, 
      '0'
    )
  ) AS company_thread_ids, 
  cscart_companies.suspend_date, 
  cscart_companies.last_time_suspended 
FROM 
  cscart_companies 
  LEFT JOIN cscart_company_descriptions ON cscart_company_descriptions.company_id = cscart_companies.company_id 
  AND cscart_company_descriptions.lang_code = 'vi' 
  LEFT JOIN cscart_vendor_plan_descriptions ON cscart_companies.plan_id = cscart_vendor_plan_descriptions.plan_id 
  AND cscart_vendor_plan_descriptions.lang_code = 'vi' 
  LEFT JOIN cscart_seo_names ON cscart_seo_names.object_id = cscart_companies.company_id 
  AND cscart_seo_names.type = 'm' 
  AND cscart_seo_names.dispatch = '' 
  AND cscart_seo_names.lang_code = 'vi' 
  LEFT JOIN cscart_discussion ON cscart_discussion.object_id = cscart_companies.company_id 
  AND cscart_discussion.object_type = 'M' 
  LEFT JOIN cscart_discussion_posts ON cscart_discussion_posts.thread_id = cscart_discussion.thread_id 
  AND cscart_discussion_posts.status = 'A' 
  LEFT JOIN cscart_discussion_rating ON cscart_discussion.thread_id = cscart_discussion_rating.thread_id 
  AND cscart_discussion_rating.post_id = cscart_discussion_posts.post_id 
WHERE 
  1 
  AND cscart_companies.status = 'A' 
  AND cscart_companies.is_featured = 'Y' 
  AND cscart_companies.is_featured = 'Y' 
GROUP BY 
  company_thread_ids 
ORDER BY 
  cscart_companies.company asc

Query time 0.00118

JSON explain

{
  "query_block": {
    "select_id": 1,
    "filesort": {
      "sort_key": "cscart_companies.company",
      "temporary_table": {
        "table": {
          "table_name": "cscart_companies",
          "access_type": "ALL",
          "rows": 4,
          "filtered": 100,
          "attached_condition": "cscart_companies.`status` = 'A' and cscart_companies.is_featured = 'Y'"
        },
        "table": {
          "table_name": "cscart_company_descriptions",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY"],
          "key": "PRIMARY",
          "key_length": "10",
          "used_key_parts": ["company_id", "lang_code"],
          "ref": ["vietpom_dev.cscart_companies.company_id", "const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_company_descriptions.lang_code = 'vi')"
        },
        "table": {
          "table_name": "cscart_vendor_plan_descriptions",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY"],
          "key": "PRIMARY",
          "key_length": "10",
          "used_key_parts": ["plan_id", "lang_code"],
          "ref": ["vietpom_dev.cscart_companies.plan_id", "const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_vendor_plan_descriptions.lang_code = 'vi')"
        },
        "table": {
          "table_name": "cscart_seo_names",
          "access_type": "ref",
          "possible_keys": ["PRIMARY", "dispatch"],
          "key": "PRIMARY",
          "key_length": "206",
          "used_key_parts": ["object_id", "type", "dispatch", "lang_code"],
          "ref": [
            "vietpom_dev.cscart_companies.company_id",
            "const",
            "const",
            "const"
          ],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_seo_names.object_id = cscart_companies.company_id and cscart_seo_names.`type` = 'm' and cscart_seo_names.dispatch = '' and cscart_seo_names.lang_code = 'vi')"
        },
        "table": {
          "table_name": "cscart_discussion",
          "access_type": "eq_ref",
          "possible_keys": ["object_id"],
          "key": "object_id",
          "key_length": "6",
          "used_key_parts": ["object_id", "object_type"],
          "ref": ["vietpom_dev.cscart_companies.company_id", "const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_discussion.object_id = cscart_companies.company_id and cscart_discussion.object_type = 'M')",
          "using_index": true
        },
        "table": {
          "table_name": "cscart_discussion_posts",
          "access_type": "ref",
          "possible_keys": ["thread_id", "thread_id_2"],
          "key": "thread_id_2",
          "key_length": "6",
          "used_key_parts": ["thread_id", "status"],
          "ref": ["vietpom_dev.cscart_discussion.thread_id", "const"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_discussion_posts.`status` = 'A' and trigcond(cscart_discussion.thread_id is not null))",
          "using_index": true
        },
        "table": {
          "table_name": "cscart_discussion_rating",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY", "thread_id"],
          "key": "PRIMARY",
          "key_length": "3",
          "used_key_parts": ["post_id"],
          "ref": ["vietpom_dev.cscart_discussion_posts.post_id"],
          "rows": 1,
          "filtered": 100,
          "attached_condition": "trigcond(cscart_discussion_rating.thread_id = cscart_discussion.thread_id and trigcond(cscart_discussion_posts.post_id is not null))"
        }
      }
    }
  }
}

Result

company_id lang_code email company timestamp status company_description plan seo_name seo_path average_rating company_thread_ids suspend_date last_time_suspended
1 vi admin@hd.com HD 1269610461 A Default Plan hd-vi-products 1_0 0 0
5 vi hyphens@email.com Hyphens Việt Nam 1689573042 A <p><em>[<b>Miễn phí giao hàng</b>&nbsp;cho tất cả sản phẩm của Hyphens Việt Nam]</em></p> <p><span class="contentpasted0"><b>Hyphens Pharma&nbsp;</b></span><span class="contentpasted0">là&nbsp;thành viên&nbsp;của&nbsp;<b>Hyphens Group.</b></span></p> <p><span class="contentpasted0"></span><span class="contentpasted0"></span><span class="contentpasted0"></span><span class="contentpasted0"><b>Hyphens</b></span><span class="contentpasted0">&nbsp;<b>Pharma&nbsp;</b>tập trung kinh doanh và tiếp thị các sản phẩm Dược phẩm tại các quốc gia Đông Nam Á thông qua kênh phân phối độc quyền hoặc cấp phép và thỏa thuận cung cấp với các thương hiệu tiêu chuẩn chủ yếu đến từ Châu Âu và Mỹ.</span></p> <p><span class="contentpasted0">Với tầm nhìn cung cấp một chất lượng sống tốt hơn cho bệnh nhân, chúng tôi liên tục theo sát nhịp đổi mới của ngành Dược để đáp ứng nhu cầu của bệnh nhân.&nbsp;<b>Hyphens</b>&nbsp;<b>Pharma</b>&nbsp;mang đến các sản phẩm dược phẩm chuyên khoa ở khắp các lĩnh vực như: da liễu, nhi khoa và sơ sinh, tai mũi họng, dị ứng, chỉnh hình, khớp, cản quang, nhãn khoa...</span></p> <p><span class="contentpasted0">Các sản phẩm chính trong danh mục đầu tư của chúng tôi bao gồm Sterimar, Dorithricin, Piascledine, Ocuvite, Liposic, Indocollyre, Rupafin.</span></p> <p>Ngoài ra,&nbsp;<b>Hyphens Pharma</b>&nbsp;còn phát triển, tiếp thị và kinh doanh chuỗi sản phẩm da liễu độc quyền dưới thương hiệu Ceradan và TDF, thực phẩm bảo vệ sức khoẻ thương hiệu Ocean Health.</p> Default Plan hyphensvn 5_0 0 0