SELECT 
  company_descriptions.*, 
  companies.*, 
  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(
    companies.company_id, 
    '_', 
    IF (
      cscart_discussion_rating.thread_id, 
      cscart_discussion_rating.thread_id, 
      '0'
    )
  ) AS company_thread_ids 
FROM 
  cscart_companies AS companies 
  LEFT JOIN cscart_company_descriptions AS company_descriptions ON company_descriptions.company_id = companies.company_id 
  AND company_descriptions.lang_code = 'en' 
  LEFT JOIN cscart_vendor_plan_descriptions ON companies.plan_id = cscart_vendor_plan_descriptions.plan_id 
  AND cscart_vendor_plan_descriptions.lang_code = 'en' 
  LEFT JOIN cscart_seo_names ON cscart_seo_names.object_id = 42 
  AND cscart_seo_names.type = 'm' 
  AND cscart_seo_names.dispatch = '' 
  AND cscart_seo_names.lang_code = 'en' 
  LEFT JOIN cscart_discussion ON cscart_discussion.object_id = 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 
  companies.company_id = 42

Query time 0.01214

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "2.10"
    },
    "nested_loop": [
      {
        "table": {
          "table_name": "companies",
          "access_type": "const",
          "possible_keys": [
            "PRIMARY"
          ],
          "key": "PRIMARY",
          "used_key_parts": [
            "company_id"
          ],
          "key_length": "4",
          "ref": [
            "const"
          ],
          "rows_examined_per_scan": 1,
          "rows_produced_per_join": 1,
          "filtered": "100.00",
          "cost_info": {
            "read_cost": "0.00",
            "eval_cost": "0.10",
            "prefix_cost": "0.00",
            "data_read_per_join": "6K"
          },
          "used_columns": [
            "company_id",
            "status",
            "company",
            "lang_code",
            "address",
            "city",
            "state",
            "country",
            "zipcode",
            "email",
            "phone",
            "url",
            "storefront",
            "secure_storefront",
            "entry_page",
            "redirect_customer",
            "countries_list",
            "timestamp",
            "shippings",
            "logos",
            "request_user_id",
            "request_account_name",
            "request_account_data",
            "tax_number",
            "registered_from_storefront_id",
            "plan_id",
            "pre_moderation",
            "pre_moderation_edit",
            "pre_moderation_edit_vendors",
            "suspend_date",
            "grace_period_start",
            "last_time_suspended",
            "last_debt_notification_time",
            "override_delivery_days",
            "delivery_days",
            "stripe_connect_account_id",
            "stripe_connect_account_type",
            "paypal_commerce_platform_account_id"
          ]
        }
      },
      {
        "table": {
          "table_name": "company_descriptions",
          "access_type": "const",
          "possible_keys": [
            "PRIMARY"
          ],
          "key": "PRIMARY",
          "used_key_parts": [
            "company_id",
            "lang_code"
          ],
          "key_length": "10",
          "ref": [
            "const",
            "const"
          ],
          "rows_examined_per_scan": 1,
          "rows_produced_per_join": 1,
          "filtered": "100.00",
          "cost_info": {
            "read_cost": "0.00",
            "eval_cost": "0.10",
            "prefix_cost": "0.00",
            "data_read_per_join": "1K"
          },
          "used_columns": [
            "company_id",
            "lang_code",
            "company_description",
            "terms",
            "i18n_company",
            "i18n_address",
            "i18n_city"
          ]
        }
      },
      {
        "table": {
          "table_name": "cscart_vendor_plan_descriptions",
          "access_type": "const",
          "possible_keys": [
            "PRIMARY"
          ],
          "key": "PRIMARY",
          "used_key_parts": [
            "plan_id",
            "lang_code"
          ],
          "key_length": "10",
          "ref": [
            "const",
            "const"
          ],
          "rows_examined_per_scan": 1,
          "rows_produced_per_join": 1,
          "filtered": "100.00",
          "cost_info": {
            "read_cost": "0.00",
            "eval_cost": "0.10",
            "prefix_cost": "0.00",
            "data_read_per_join": "792"
          },
          "used_columns": [
            "plan_id",
            "lang_code",
            "plan"
          ]
        }
      },
      {
        "table": {
          "table_name": "cscart_seo_names",
          "access_type": "ref",
          "possible_keys": [
            "PRIMARY",
            "dispatch"
          ],
          "key": "PRIMARY",
          "used_key_parts": [
            "object_id",
            "type",
            "dispatch",
            "lang_code"
          ],
          "key_length": "206",
          "ref": [
            "const",
            "const",
            "const",
            "const"
          ],
          "rows_examined_per_scan": 1,
          "rows_produced_per_join": 1,
          "filtered": "100.00",
          "cost_info": {
            "read_cost": "0.25",
            "eval_cost": "0.10",
            "prefix_cost": "0.35",
            "data_read_per_join": "1K"
          },
          "used_columns": [
            "name",
            "object_id",
            "type",
            "dispatch",
            "path",
            "lang_code"
          ]
        }
      },
      {
        "table": {
          "table_name": "cscart_discussion",
          "access_type": "const",
          "possible_keys": [
            "object_id"
          ],
          "key": "object_id",
          "used_key_parts": [
            "object_id",
            "object_type"
          ],
          "key_length": "6",
          "ref": [
            "const",
            "const"
          ],
          "rows_examined_per_scan": 1,
          "rows_produced_per_join": 1,
          "filtered": "100.00",
          "cost_info": {
            "read_cost": "0.25",
            "eval_cost": "0.10",
            "prefix_cost": "0.70",
            "data_read_per_join": "24"
          },
          "used_columns": [
            "thread_id",
            "object_id",
            "object_type"
          ]
        }
      },
      {
        "table": {
          "table_name": "cscart_discussion_posts",
          "access_type": "ref",
          "possible_keys": [
            "thread_id",
            "thread_id_2"
          ],
          "key": "thread_id",
          "used_key_parts": [
            "thread_id"
          ],
          "key_length": "3",
          "ref": [
            "wearethehelpful_scalesta_net.cscart_discussion.thread_id"
          ],
          "rows_examined_per_scan": 2,
          "rows_produced_per_join": 2,
          "filtered": "100.00",
          "cost_info": {
            "read_cost": "0.50",
            "eval_cost": "0.20",
            "prefix_cost": "1.40",
            "data_read_per_join": "896"
          },
          "used_columns": [
            "post_id",
            "thread_id",
            "status"
          ],
          "attached_condition": "<if>(is_not_null_compl(cscart_discussion_posts), (`wearethehelpful_scalesta_net`.`cscart_discussion_posts`.`status` = 'A'), true)"
        }
      },
      {
        "table": {
          "table_name": "cscart_discussion_rating",
          "access_type": "eq_ref",
          "possible_keys": [
            "PRIMARY",
            "thread_id"
          ],
          "key": "PRIMARY",
          "used_key_parts": [
            "post_id"
          ],
          "key_length": "3",
          "ref": [
            "wearethehelpful_scalesta_net.cscart_discussion_posts.post_id"
          ],
          "rows_examined_per_scan": 1,
          "rows_produced_per_join": 2,
          "filtered": "100.00",
          "cost_info": {
            "read_cost": "0.50",
            "eval_cost": "0.20",
            "prefix_cost": "2.10",
            "data_read_per_join": "32"
          },
          "used_columns": [
            "rating_value",
            "post_id",
            "thread_id"
          ],
          "attached_condition": "<if>(is_not_null_compl(cscart_discussion_rating), (`wearethehelpful_scalesta_net`.`cscart_discussion_rating`.`thread_id` = `wearethehelpful_scalesta_net`.`cscart_discussion`.`thread_id`), true)"
        }
      }
    ]
  }
}

Result

company_id lang_code company_description terms i18n_company i18n_address i18n_city status company address city state country zipcode email phone url storefront secure_storefront entry_page redirect_customer countries_list timestamp shippings logos request_user_id request_account_name request_account_data tax_number registered_from_storefront_id plan_id pre_moderation pre_moderation_edit pre_moderation_edit_vendors suspend_date grace_period_start last_time_suspended last_debt_notification_time override_delivery_days delivery_days stripe_connect_account_id stripe_connect_account_type paypal_commerce_platform_account_id plan seo_name seo_path average_rating company_thread_ids
42 en <p>Tired Mums Coffee is committed to supporting others through blending the smoothest coffees, that are bursting with flavour and goodness.</p> <p>We believe your daily coffee ritual is about more than just caffeine, it can provide the space to breath, re-connect and REVIVE - one cup at a time. </p> <p>Our coffee is blended by mums who have experienced first hand the challenges of balancing NHS careers, parenthood and personal well-being.</p> <p>We're passionate about coffee and the positive impact it can have, and have created the smoothest coffees that can get you through the entire day.</p> <p>Our community is growing and we remain committed to donating 1% of all coffee sales to charities that support parents.</p> <h2>Order processing time</h2> <p>Orders will be processed and shipped the following business day after orders are placed.</p> <h2>Delivery service</h2> <p>Our standard delivery service is Royal Mail Tracked 48.</p> <h2>Delivery charges</h2> <p>Postage and packing will be charged as follows:</p> <ul><li>£3.95 per order for Royal Mail Tracked 48</li></ul> <h1></h1> <h1>Refund policy</h1> <p>We work tirelessly to bring you products that you’ll love however if you are not satisfied with your order for any reason, please don’t hesitate to contact us by email at&nbsp;hello@tiredmumscoffee.co.uk&nbsp;and we will look into this for you.</p> <h2>Coffee</h2> <p>We cannot accept returned goods due to their perishable nature. If you are dissatisfied or if there is a problem with your order, please contact us within 7 days of receipt of your order. We will then investigate the issue and remedy the situation either through the delivery of a replacement or a refund of the purchase price.</p> <h2>Brewing kit and merchandise</h2> <p>If you are not satisfied with the items purchased or if an item has arrived damaged, you have 28 days to inform us of the issue by email. We will then investigate the issue and will contact you to remedy the situation either through the delivery of a replacement or a refund of the purchase price. We will also collect the original goods received.</p> <p>Items that are returned without an issue of condition or functionality on delivery must be returned in their original packaging, unused and undamaged with all parts and documentation included i.e. in full sellable condition.</p> <p>Please do not send your purchase back to the manufacturer.</p> <p>If 28 days have passed since your purchase, unfortunately, we can’t offer you a refund or exchange.</p> <h2>Proof of purchase</h2> <p>To complete your return, we require a receipt or proof of purchase.</p> <h2>Refunds</h2> <p>Once your return is received, we will notify you by email. We will then inspect the item and notify you of the approval or rejection of your refund by email. If the refund is approved, we will process your refund and this will be applied to the original method of payment.</p> <h2>Late or missing refunds</h2> <p>If your refund has not been received, please contact your bank or credit card company in the first instance as there is often a processing time before a refund is received.</p> <h2>Sale items</h2> <p>Unfortunately, sale items cannot be refunded.</p> <h2>Exchanges</h2> <p>We only offer replacements if items are defective or damaged. If an exchange is required, please get in touch via email and we will provide a delivery address for the return.</p> <h2>Gift</h2> <p>If the item was marked as a gift when purchased and shipped directly to you, you’ll receive a gift credit for the value of your return. A gift certificate will be emailed to you once the return is received.</p> <h2>Shipping Returns</h2> <p>Please get in touch via email and we will provide a delivery address for the return.</p> <p>You will be responsible for paying for your own shipping costs. If you are shipping an item over £30, we recommend you use a tracked service.</p> <p>Shipping costs are non-refundable. If you receive a refund, the cost of shipping will be deducted from your refund.</p> <p>Depending on the shipping address, the time it takes for an exchanged product to reach you may vary.</p> <h2>Cancellations</h2> <p>You have the right to cancel orders without reason (unless they are to your personal specification). The cancellation period expires 7 working days from the day after you receive our products.</p> <h2>Return policy queries</h2> <p>Please contact&nbsp;hello@tiredmumscoffee.co.uk&nbsp;for any other Return Policy queries.</p> <p><br></p> <p><br></p> <p></p> Tired Mums Coffee Limited A Tired Mums Coffee Limited hello@tiredmumscoffee.co.uk +447712761115 none Y 1750160357 33 0 a:4:{s:14:"company_fields";a:6:{i:37;s:5:"Laura";i:38;s:5:"Peill";i:53;s:29:"Speciality coffee and gifting";i:54;s:31:"Coffee and gifts e.g. gift sets";i:55;s:42:"Parents Gift buyers Smooth coffee lovers";i:56;s:12:"Food & drink";}s:15:"admin_firstname";s:5:"Laura";s:14:"admin_lastname";s:5:"Peill";s:6:"fields";a:0:{}} 475838539 1 9 N N N 0 0 0 0 N 0 acct_1RayqiFaKrUUonOL S Launch - 15% tired-mums-coffee-limited 42_0