I have a database that tracks user clicks. If someone clicks on the same thing twice it may produce duplicate entries in the database with the same timestamp.
Is there a way to modify my query to only return results with unique timestamps and not the duplicates.
$stmt1 = $dbConn1->prepare("
SELECT count(*)
FROM asset_lookup
");
Notes:
The join to
productis 100% equivalent to anINNERjoin because you useproduct.product_type_id = 2in theWHEREclause. Besides that, is there a point to count clicks for products that don’t exist in theproducttable and only in theassettable (if there are any)?The
LEFTjoin toeventis 100% equivalent to anINNERjoin because you useevent.activation_datein theWHEREclause.The join to
tracking_product_lookupseems completely useless.The
COUNT(*)may give wrong results with outer joins.COUNT(*)counts rows in the intermediate result set and the outer joins produce rows with Nulls in some columns (for example a product with no clicks at all, would still show a count of 1).COUNT(DISTINCT column), notCOUNT(*).The query would be written as: