Query on two different tables in the same select

0

I need to perform a search on two different tables and give echo in the results separately! I think it would look something like this:

$consulta = "SELECT * FROM tabela1 T1 UNION (SELECT* FROM tabela2 T2)";
$con = mysqli_query ($db,$consulta);
while ($Dado = mysqli_fetch_array($con)) {
  echo $DadosT1; // Aqui resultado da primeira tabela
  echo $DadosT2; // Aqui resultado da segunda tabela
}

Can anyone clarify me if this is possible and how do I do it?

    
asked by anonymous 18.11.2018 / 02:01

1 answer

1

Could not you perform separately to achieve your goal? Something like:

$consulta = "SELECT * FROM tabela1";
$con = mysqli_query ($db,$consulta);
while ($Dado = mysqli_fetch_array($con)) {
  echo $Dado; // Aqui resultado da primeira tabela
}

$consulta = "SELECT* FROM tabela2 T2";
$con = mysqli_query ($db,$consulta);
while ($Dado = mysqli_fetch_array($con)) {
  echo $Dado; // Aqui resultado da segunda tabela
}

Sorry if I did not understand your goal correctly.

    
18.11.2018 / 05:54