I am trying to follow the answer given in " Retrieving the last record in each group " but I have a problem
My problem is that I am echoing both Y78430's (ie count 1 and 3) when I only want to echo count 3
I am trying to pick the last record of groups of data where the last record is the lower alphabetical letter.
Example of my data here (Table is 'schedulelocation'):-
Count cif_train_uid cif_stp_indicator Other Data
1 Y78430 p zzzzzzz
2 Z45012 p fffffff
3 Y78430 o sssssss
In the above data there are 2 X Y78430. I would like to echo only one of these. The one with a cif_stp_indicator of o - ie its lower in the alphabet than the 'p'
Here is my code :-
$b="SELECT s1.cif_train_uid,s1.cif_stp_indicator,s1.schedule_start_date
FROM schedulelocation s1
LEFT JOIN schedulelocation s2
ON (s1.cif_train_uid AND s1.cif_stp_indicator < s2.cif_stp_indicator)
WHERE s2.cif_stp_indicator is Null AND s1.cif_train_uid='Y78430' ";
$l=mysqli_query($mysql_link,$b);
if ($l) {
while($berths=mysqli_fetch_array($l,MYSQLI_ASSOC))
{
echo $berths['cif_train_uid'];
echo $berths['cif_stp_indicator'];
echo $berths['schedule_start_date'];
echo "</b>";
echo "</b>";
}
}
Any help greatly appreciated. Thanks