INNER JOIN with equal columns conflict

2

In this SELECT JOIN , all tables have columns with the same name. With this, it gives a conflict at the time of listing.

Example: column Id_saida it is in all tables. How to list each one?

$cmd = "SELECT f.*,a.*,e.*,p.*,m.*,v.* FROM a_finan AS f

       INNER JOIN agenda_saidas AS a
       ON a.id_saida    = f.id_saida

       LEFT JOIN empresas AS e
       ON e.id_empresa  = f.id_empresa

       LEFT JOIN passageiros AS p
       ON p.id_saida    = f.id_saida

       LEFT JOIN motoristas AS m
       ON m.id    = a.id_motorista

       LEFT JOIN veiculos AS v
       ON v.id_veiculo    = a.id_veiculo


       where a.id_transfer1 = '$id_transfer'  AND f.id_transfer =  
       '$id_transfer' 
       AND e.id_transfer  = '$id_transfer'  
       AND a.start BETWEEN '$de' AND '$ate' 
       ";

    $produtos = mysql_query($cmd);
    $total = mysql_num_rows($produtos);
    while ($linha = mysql_fetch_array($produtos)) {

     $id_saida = $linha['id_saida'];  // Coluna id_saida em todas as tabelas
     $id_saida = $linha['id_saida'];  // tabela 2
     $id_saida = $linha['id_saida'];  // tabela 3
     }
    
asked by anonymous 28.08.2015 / 17:25

1 answer

6

Assign the value of the field to a reference eg in select use

SELECT p.id_saida as id_saidaTabelap, p.id_saida as id_saidaTabelaf

And when you get the value, do it

$id_saidaP = $linha['id_saidaTabelap'];  // tabela 2
$id_saidaF = $linha['id_saidaTabelaf'];  // tabela 3
    
28.08.2015 / 17:31