This will pull the amount of the record with the highest ID of the campaign called Car.
and will pull the amount of the record with the highest ID of the campaign called Van, and so on in the IN(*) part.
It then adds them altogether, and outputs in $dog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$result = mysql_query("SELECT amount FROM table1 JOIN ( SELECT MAX(id) as id FROM cmdata WHERE campaign IN ('Car', 'Van', 'Bike', 'Bus') GROUP BY campaign) t ON t.id = cmdata.id"); while($row = mysql_fetch_array($result)) { $sum = $row['amount']; $dog = $dog + $sum; } echo "<br>There are $dog"; |