SELECT 
  company_descriptions.*, 
  companies.*, 
  vendor_plan_descriptions.plan, 
  seo_names.name as seo_name, 
  seo_names.path as seo_path, 
  vendor_ga_tracking_code, 
  vendor_fb_tracking_code, 
  AVG(discussion_rating.rating_value) AS average_rating, 
  CONCAT(
    companies.company_id, 
    '_', 
    IF (
      discussion_rating.thread_id, discussion_rating.thread_id, 
      '0'
    )
  ) AS company_thread_ids 
FROM 
  companies AS companies 
  LEFT JOIN company_descriptions AS company_descriptions ON company_descriptions.company_id = companies.company_id 
  AND company_descriptions.lang_code = 'en' 
  LEFT JOIN vendor_plan_descriptions ON companies.plan_id = vendor_plan_descriptions.plan_id 
  AND vendor_plan_descriptions.lang_code = 'en' 
  LEFT JOIN seo_names ON seo_names.object_id = 66 
  AND seo_names.type = 'm' 
  AND seo_names.dispatch = '' 
  AND seo_names.lang_code = 'en' 
  LEFT JOIN discussion as discussionA ON discussionA.object_id = companies.company_id 
  AND discussionA.object_type = 'M' 
  LEFT JOIN discussion_posts ON discussion_posts.thread_id = discussionA.thread_id 
  AND discussion_posts.status = 'A' 
  LEFT JOIN discussion_rating ON discussionA.thread_id = discussion_rating.thread_id 
  AND discussion_rating.post_id = discussion_posts.post_id 
WHERE 
  companies.company_id = 66

Query time 0.00197

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "2.79"
    },
    "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": "14K"
          },
          "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",
            "plan_id",
            "stripe_connect_account_id",
            "identifier_facebook_pixel",
            "featured_products",
            "sd_ga_tracking_code",
            "paypal_commerce_platform_account_id",
            "tagline",
            "url_facebook",
            "url_instagram",
            "url_twitter",
            "url_pinterest",
            "announcement",
            "shippo_api_token",
            "shippo_carrier",
            "shippo_service_type",
            "vendor_ga_tracking_code",
            "vendor_fb_tracking_code",
            "custom_domain",
            "custom_domain_status",
            "taxjar_key",
            "taxjar_export_statuses",
            "taxjar_export_csv_data",
            "ag_hide_city",
            "updated_timestamp",
            "suspend_date",
            "grace_period_start",
            "last_time_suspended",
            "last_debt_notification_time",
            "tax_number",
            "stripe_connect_account_type",
            "registered_from_storefront_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",
            "subdomain_colors",
            "i18n_company",
            "i18n_address",
            "i18n_city"
          ]
        }
      },
      {
        "table": {
          "table_name": "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": "1K"
          },
          "used_columns": [
            "plan_id",
            "lang_code",
            "plan"
          ]
        }
      },
      {
        "table": {
          "table_name": "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.84",
            "eval_cost": "0.10",
            "prefix_cost": "0.94",
            "data_read_per_join": "1K"
          },
          "used_columns": [
            "name",
            "object_id",
            "type",
            "dispatch",
            "path",
            "lang_code"
          ]
        }
      },
      {
        "table": {
          "table_name": "discussionA",
          "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",
          "using_index": true,
          "cost_info": {
            "read_cost": "0.71",
            "eval_cost": "0.10",
            "prefix_cost": "1.75",
            "data_read_per_join": "24"
          },
          "used_columns": [
            "thread_id",
            "object_id",
            "object_type"
          ]
        }
      },
      {
        "table": {
          "table_name": "discussion_posts",
          "access_type": "ref",
          "possible_keys": [
            "thread_id",
            "thread_id_2"
          ],
          "key": "thread_id_2",
          "used_key_parts": [
            "thread_id",
            "status"
          ],
          "key_length": "6",
          "ref": [
            "goimagine.discussionA.thread_id",
            "const"
          ],
          "rows_examined_per_scan": 1,
          "rows_produced_per_join": 1,
          "filtered": "100.00",
          "using_index": true,
          "cost_info": {
            "read_cost": "0.25",
            "eval_cost": "0.18",
            "prefix_cost": "2.17",
            "data_read_per_join": "787"
          },
          "used_columns": [
            "post_id",
            "thread_id",
            "status"
          ]
        }
      },
      {
        "table": {
          "table_name": "discussion_rating",
          "access_type": "eq_ref",
          "possible_keys": [
            "PRIMARY",
            "thread_id"
          ],
          "key": "PRIMARY",
          "used_key_parts": [
            "post_id"
          ],
          "key_length": "3",
          "ref": [
            "goimagine.discussion_posts.post_id"
          ],
          "rows_examined_per_scan": 1,
          "rows_produced_per_join": 1,
          "filtered": "100.00",
          "cost_info": {
            "read_cost": "0.44",
            "eval_cost": "0.18",
            "prefix_cost": "2.79",
            "data_read_per_join": "28"
          },
          "used_columns": [
            "rating_value",
            "post_id",
            "thread_id"
          ],
          "attached_condition": "<if>(is_not_null_compl(discussion_rating), (`goimagine`.`discussion_rating`.`thread_id` = `goimagine`.`discussionA`.`thread_id`), true)"
        }
      }
    ]
  }
}

Result

company_id lang_code company_description terms subdomain_colors 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 plan_id stripe_connect_account_id identifier_facebook_pixel featured_products sd_ga_tracking_code paypal_commerce_platform_account_id tagline url_facebook url_instagram url_twitter url_pinterest announcement shippo_api_token shippo_carrier shippo_service_type vendor_ga_tracking_code vendor_fb_tracking_code custom_domain custom_domain_status taxjar_key taxjar_export_statuses taxjar_export_csv_data ag_hide_city updated_timestamp suspend_date grace_period_start last_time_suspended last_debt_notification_time tax_number stripe_connect_account_type registered_from_storefront_id plan seo_name seo_path average_rating company_thread_ids
66 en <h4 class="text-center"><strong>Jewelry and Gifts inspired by the Sea&nbsp;</strong></h4> <h4 class="text-center"><strong>Handcrafted Jewelry reminding you of a relaxed and easy day at the beach...</strong></h4> <h4 class="text-center"></h4> <p class="text-center">All the "bits off the beach" bring their own inspirations. The color, texture, size or shape of each piece speaks it's own story. I try to bring each to life in it's own special way for you to enjoy.&nbsp;My favorites are sea glass, shells, beach stones and sea beans.&nbsp; I add quality, modern components to offer everything from pendant necklaces, earrings, anklets and belly rings to book marks and wind chimes.<br></p> <h5 class="text-center"></h5> <h4>Welcome to Bits off the Beach!</h4> <p><span style="color: inherit; font-family: inherit; font-weight: 600;">Returns and exchanges</span><br></p> <p>I gladly accept returns, exchanges, and cancellations&nbsp;</p> <p>• Contact me within 7 days of delivery.</p> <p>• Ship items back with 14 days of delivery.</p> <p>• Request a cancellation before item has been shipped.</p> <p><br></p> <h5>Returns and exchange details&nbsp;</h5> <p>&nbsp;What To Do If Things Go Wrong?&nbsp;</p> <p>&nbsp;I want you to be comfortable shopping with me. Please let me know if you aren't 100% in love with your new purchase. It can be returned in its original condition for 14 days after delivery for a full refund. Your piece of jewelry is guaranteed against breaking for any reason for 60 days from date of delivery! I am happy to repair it and return it to you or to give you an in-shop credit for the purchase price. Return shipping to me will be your responsibility, I will pay for shipping back to you.<br></p> <p>Items lost in the mail will be replaced once we both have exhausted all avenues to try and find where it went. It often is just as simple as checking that the neighbor didn't get it or the mailman didn't stashed it in the bushes for "safe keeping"! I do ship with delivery confirmation and tracking for your comfort and security in knowing what's up during shipping.<br></p> <p>If there is a problem with your purchase, as each item is individually made and often are unique pieces, I can only replace with as close a match as possible of an equivalent item or a refund. Hopefully, none of that will be needed, but it's nice to know that I am on your side if it becomes necessary. Thanks for shopping with me!<br></p> <h5><strong>Shipping</strong></h5> <p>How Do I Get It?</p> <p>I normally send out your item within 1 to 2 business day unless otherwise noted. First class USPS with tracking and confirmation. You may also choose US Priority, a shipping up-grade, under the shipping options on most listings for delivery within the U.S.</p> <p><br></p> <p>Please double-check that you have the correct address listed on your purchase order. If it is returned as undeliverable after being sent, I can not refund the shipping fee. To re-send there will be a minimum charge of 3.00 shipping charge, depending on the weight and location of your purchase.</p> <p><br></p> <p></p> <h5><strong>Additional&nbsp; FAQs</strong></h5> <p>Don't See What You Need?</p> <p>Custom orders are welcome. If you have a special item you would like to be made into something you can wear, let me know what you have in mind and we can work together to see what we can come up with. To place a custom order, contact me by message or email, we can agree on the item to be produced and a listing is made with the link sent by message. Next you need to make the purchase in the normal way, and upon payment being received, the order will be processed and mailed. You will be notified at the point of posting.<br>Purchase and payment must be made within 3 days or your item will be open to buy to the general public.</p> <p></p> <h6></h6> <p><b class="btn btn-link prompt no-wrap ml-xs-1 text-link-primary" style="margin-left: 6px; border-radius: 3px; border-width: initial; border-style: none; border-color: initial; font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit; padding: 0px; text-decoration-line: underline; user-select: none; white-space: nowrap; -webkit-tap-highlight-color: transparent; -webkit-appearance: none; background-color: transparent; color: rgb(34, 34, 34);"><br></b></p> <p><b class="btn btn-link prompt no-wrap ml-xs-1 text-link-primary" style="margin-left: 6px; border-radius: 3px; border-width: initial; border-style: none; border-color: initial; font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit; padding: 0px; text-decoration-line: underline; user-select: none; white-space: nowrap; -webkit-tap-highlight-color: transparent; -webkit-appearance: none; background-color: transparent; color: rgb(34, 34, 34);"><br></b></p> <p><b class="btn btn-link prompt no-wrap ml-xs-1 text-link-primary" style="margin-left: 6px; border-radius: 3px; border-width: initial; border-style: none; border-color: initial; font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit; padding: 0px; text-decoration-line: underline; user-select: none; white-space: nowrap; -webkit-tap-highlight-color: transparent; -webkit-appearance: none; background-color: transparent; color: rgb(34, 34, 34);"><br></b><br></p> <p><b class="btn btn-link prompt no-wrap ml-xs-1 text-link-primary" style="margin-left: 6px; border-radius: 3px; border-width: initial; border-style: none; border-color: initial; font-family: inherit; font-size: inherit; font-weight: inherit; height: inherit; line-height: inherit; padding: 0px; text-decoration-line: underline; user-select: none; white-space: nowrap; -webkit-tap-highlight-color: transparent; -webkit-appearance: none; background-color: transparent; color: rgb(34, 34, 34);"></b></p> {"tmenu_style":"V","default_colors":"N","link_color":"#007d89","label_color":"#00a0af","icon_color":"#00a0af","main_btn_color":"#6dd1d6","branded_text_color":"#00a0af","vbp_1_url":"","vbp_2_url":"","vbp_3_url":"","vba_1_url":"","vba_2_url":"","vba_3_url":""} BitsofftheBeach PO BOX 475 EAST OLYMPIA A BitsofftheBeach PO BOX 475 EAST OLYMPIA WA US 98540 jodiesme@comcast.net none Y 1584477334 0 a:4:{s:14:"company_fields";a:2:{i:37;s:2:"Jo";i:38;s:7:"Watkins";}s:15:"admin_firstname";s:2:"Jo";s:14:"admin_lastname";s:7:"Watkins";s:6:"fields";a:0:{}} 3 acct_1GNRTeA3U5q3QEDV 62880,61097,70191,71789,10268,167240 XUY3AXKQ6VKB6 Jewelry and Gifts Inspired by the Sea https://www.facebook.com/BitsOffTheBeach/ https://www.instagram.com/bitsoffthebeach/ https://www.pinterest.com/jodiesme A {"items_per_file":"2500","time_from":"","time_to":""} N 0 0 0 0 0 S Professional Plan bitsoffthebeach 0.0000 66_1183