$sql = "SELECT orders_code, orders_by_code, orders_id, orders_status, DATE_FORMAT(orders_create_date,'%Y-%m') AS orders_date FROM tb_orders WHERE orders_status = 1 AND DATE_FORMAT(orders_create_date, '%Y-%m') = '2009-10' ";
ได้จำนวนแถวที่ได้คือ 93 ใบ
กับโค้ดที่ใช้ LEFT JOIN
Code (PHP)
$sql = "SELECT orders_code, orders_by_code, orders_id, orders_status, DATE_FORMAT(orders_create_date,'%Y-%m') AS orders_date FROM tb_orders LEFT JOIN tb_members ON tb_orders.orders_by_code = tb_members.members_code WHERE orders_status = 1 AND DATE_FORMAT(orders_create_date, '%Y-%m') = '2009-10' ";
$sql = "SELECT orders_code, orders_by_code, orders_id, orders_status, DATE_FORMAT(orders_create_date,'%Y-%m') AS orders_date FROM tb_orders LEFT JOIN tb_members ON tb_orders.orders_by_code = tb_members.members_code WHERE orders_status = 1 AND DATE_FORMAT(orders_create_date, '%Y-%m') = '2009-10' ";
เป็น Code (PHP)
$sql = "SELECT DISTINCT orders_code, orders_by_code, orders_id, orders_status, DATE_FORMAT(orders_create_date,'%Y-%m') AS orders_date FROM tb_orders LEFT JOIN tb_members ON tb_orders.orders_by_code = tb_members.members_code WHERE orders_status = 1 AND DATE_FORMAT(orders_create_date, '%Y-%m') = '2009-10' ";