Home / Create MySQL View

Create MySQL View

CREATE VIEW products_trending AS

SELECT `ProductID`, `P_Title`,

(SELECT `product_analysis`.`An_SaleDate` as oldest_sale_date FROM `product_analysis`
WHERE `product_analysis`.`An_ProductID` = `products`.`ProductID`
ORDER BY `An_SaleDate` ASC
LIMIT 1
) as oldest_sale_date,

(SELECT `product_analysis`.`An_SaleDate` as latest_sale_date FROM `product_analysis`
WHERE `product_analysis`.`An_ProductID` = `products`.`ProductID`
ORDER BY `An_SaleDate` DESC
LIMIT 1
) as latest_sale_date

FROM `products`

all rights reserved