Sql problems with disntinct

Asked

Viewed 82 times

1

I have a table in my database with:

  • horarioId
  • horarioParagemId
  • horarioLinhaId
  • horarioHora

Do INNER JOIN of the table rows:

  • linhaId
  • linhaNome

Do INNER JOIN of the table stops:

  • paragemId
  • paragemRua
  • paragemLatitude
  • paragemLongitude

    Example of the schedule table

Horarioid : 1 scheduleParagemId : 3 hourly Table : 4 hourly Time :22:00:00

Horarioid : 2 scheduleParagemId : 3 hourly Table : 4 hoursHora :21:00:00

The goal is to only receive the coordinates where the id of the stops are different. The code I made works with paragemLatitude or paragemLongitude, but does not work with paragemId

include_once('seguranca.php');
protegePagina();

$sql="SELECT DISTINCT horarioParagemId
      FROM horarios
      INNER JOIN paragens ON paragemId = horarioParagemId
      INNER JOIN linhas ON horarioLinhaId = linhaId
      WHERE horariolinhaId = " . $_GET['filtrapronto'];

$_SESSION['latitudefiltra']= array();
$_SESSION['longitudefiltra']= array();
$result=mysqli_query($con,$sql);

while($dados=mysqli_fetch_array($result)) {

    $_SESSION['latitudefiltra'] [] = $dados['paragemLatitude'];
    $_SESSION['longitudefiltra'] []  = $dados['paragemLongitude'];
}

$obj = new stdClass();
$obj->Latitudes=$_SESSION['latitudefiltra'];
$obj->Longitudes=$_SESSION['longitudefiltra'] ; 
echo json_encode($obj);
  • You can illustrate the expected result?

  • This is what you want: http://sqlfiddle.com/#! 9/5535ec/4 ? If not, tell us an example of records you have and what result you expect.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.