I have a table where a filed contains roll numbers like so:
id | roll_no
--------------
1 | 290320452
2 | 290320453
3 | 290340454
4 | 290330455
from the above column I want roll_no with matching position 4 AND 5 with 32.
where the result would be
id | roll_no
--------------
1 | 290320452
2 | 290320453
For now I have done by filtering the result array like so:
$subject_code = 32;
foreach($result as $row){
if($subject_code != NULL){
if(substr($row['roll_no'],3,2) == $subject_code){
$data[] = $row['roll_no'];
}
}
else{
$data[] = $row['roll_no'];
}
}
Is there a better way to filter while querying on mysql query.
I have seen SUBSTRING() function of mysql but no help.
1 Answer