the idea is to show the consultations by career
in the following image: the first 4 records on the right are of the second race and the last 4 of the first race and it is wrong, for example the query on the left shows me that it is the Second Race and the query of the right should show me only the first 4 records that are those associated with the second race the problem is that
The relationship is as follows: carreras_caballos.id_carreras_caballos=ejemplar.id_carreras_caballos
annex the image and queries
<?php
$sql2 = "SELECT
carreras_caballos.id_carreras_caballos,
carreras_caballos.id_carreras,
ejemplar.id_ejemplar,
ejemplar.id_carreras_caballos,
ejemplar.ejemplar,
ejemplar.peso,
ejemplar.dividendo,
ejemplar.porcentaje,
ejemplar.total
FROM carreras_caballos
INNER JOIN ejemplar ON carreras_caballos.id_carreras_caballos=ejemplar.id_carreras_caballos
ORDER BY carreras_caballos.id_carreras_caballos=ejemplar.id_carreras_caballos AND carreras_caballos.id_carreras = 1
";
$consulta = $DB_con->prepare($sql2);
$consulta->execute();
if($consulta->rowCount() > 0){
$i=1;
?>