Join query shows one record less

Hi folks,

Strange.

	$query = $db->prepare("SELECT count(vehicle_id) as tot
						   FROM dn_buys
						   WHERE (purchase_date BETWEEN " . "'". $from_date . "'" .  " AND " . "'" . $to_date . "')");

840 Records

	$query = $db->prepare("SELECT * 
						   FROM dn_buys	
						   INNER JOIN dn_sales 
						   ON dn_buys.vehicle_id = dn_sales.vehicle_id
						   WHERE (dn_buys.purchase_date BETWEEN " . "'". $from_date . "'" .  " AND " . "'" . $to_date . "') 
						   ORDER BY dn_buys.vehicle_id DESC");

839 Records

That means some record in dn_buys has no pair in dn_sales.

1 Like

Since you’re using prepared statements, you shouldn’t be putting $from_date and $to_date in your query strings…

1 Like

Thanks, i understand. so ill check further for the missing record in a separate audit.