SELECT s.id
, s.qty
, s.price
, s.date
, p.name
FROM sales s
LEFT
JOIN products p
ON s.product_id = p.id
ORDER
BY s.date DESC
LIMIT 5
function find_sale_by_dates($start_date,$end_date){ global $db;
$start_date = date("Y-m-d", strtotime($start_date));
$end_date = date("Y-m-d", strtotime($end_date));
$sql = "
SELECT s.date
, p.name
, p.sale_price
, p.buy_price
, COUNT(s.product_id) total_records
, SUM(s.qty) total_sales
, SUM(p.sale_price * s.qty) total_saleing_price
, SUM(p.buy_price * s.qty) total_buying_price
FROM sales s
LEFT
JOIN products p
ON s.product_id = p.id
WHERE s.date BETWEEN '$start_date' AND '$end_date'
GROUP
BY DATE(s.date)
, p.name
ORDER
BY DATE(s.date) DESC
"; return $db->query($sql);
}