I'm running the a query to return all results where a serial number has been entered more than once as follows:
SELECT * FROM spin
WHERE `serial` in (
SELECT `serial` from spin group by `serial`
HAVING count(*) > 1
) ORDER BY date ASC
$query = $this->db->prepare($sql);
$query->execute();
return $query->fetchAll();
It works as expected but I want to filter this out to only show one of the values with its count of occurrences. I'm guessing it will need some sort of distinct adding to the query to get a unique value back but not sure how to implement this in the best way?
For anyone intrest this is how I'm returning the data (code shortened):
<thead>
<tr>
<th>Serial</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($spins as $spin) { ?>
<tr>
<td><?php if (isset($spin->serial)) echo $spin->serial; ?></td>
<td><?php if (isset($spin->test_started)) echo $spin->date; ?></td>
</tr>
<?php } ?>
</tbody>