show queries by careers

2

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;
 ?>
    
asked by yoclens 24.01.2018 в 21:59
source

2 answers

1

ready and I could solve the solution annexed:

 <?php
     $sql2 = "SELECT * FROM ejemplar WHERE id_carreras_caballos = (SELECT MAX(id_carreras_caballos) from ejemplar)";
     $consulta = $DB_con->prepare($sql2);
     $consulta->execute();
     if($consulta->rowCount() > 0){
     $i=1;
?>

thank you all ...

    
answered by 24.01.2018 / 23:42
source
0

You do not have a where in your query, ORDER BY carrera_caballos.id_carreras_caballos = ejemplo.id_carreras_caballos AND carreras_caballos.id_carreras = 1 this part is wrong instead of order by you should have the where example ... INNER JOIN exemplary ON carreras_caballos.id_carreras_caballos = ejemplar.id_carreras_caballos
 WHERE carreras_caballos.id_carreras = 1 and remove again carrera_caballos.id_carreras_caballos = exempla.id_carreras_caballos since that relationship is in the inner

    
answered by 24.01.2018 в 22:28