Saturday 21 September 2019

SQL JOIN example

EXPLAIN
SELECT
    p.ID,
    p.entity_ID entity_ID,
    p.product_type,
    p.product_name,
    p.product_keyword,
    p.order_qty_min AS qmn,
    p.pref_selling_price AS sp,
    p.country,
    p.state,
    p.product_category,
    p.Shipping_from,
    p.selling_price_max AS maxSellingPrice,
    p.selling_price_min AS minSellingPrice,
    pp.order_qty_price AS sp,
    pp.order_qty_unit AS ou,
    pp.order_qty_max AS qmx,
    pp.order_qty_min AS qmn,
    AVG(r.rating) AS productRating,
    c.company_name AS Title,
    c.about_company AS Description,
    c.contact_email AS Email,
    c.ID AS sellerID,
    c.company_city,
    c.countryid
FROM
    product AS p
LEFT JOIN product_rating AS r
ON
    p.ID = r.product_id
LEFT JOIN \company AS c
ON
    p.entity_ID = c.entity_ID
LEFT JOIN product_price_detail AS pp
ON
    pp.products_id = p.ID
WHERE
    p.ID = 'Prod5d84a4f8af065'
GROUP BY
    p.ID

No comments:

Post a Comment