MySQL pesquisar as mesmas colunas em tabelas diferentes sem duplicar

A idéia aki é puxar valores de uma mesma coluna que está em duas tabelas diferentes sem duplicar.
Por exemplo: eu tenho SANTOS na TABELA1 e na TABELA2  e tenho MANAUS na TABELA1 e tenho SUAPE na TABELA2.

O resultado será:
  • Manaus
  • Santos
  • Suape

<select name='Porto' id='Porto'>
<?php
  $sql='';$err='';$linha='';
  $sql=mysql_query("
(select DISTINCT PORTO from TABELA1 where O_Q_VC_QUISER='REPOSTA Q PRECISAR')
                    UNION
 (select DISTINCT PORTO from TABELA2 where O_Q_VC_QUISER='REPOSTA Q PRECISAR')
                    order by PORTO // notem q o order by fica fora do select
                    ");
 
  $err=mysql_error();
  if ($err) echo "<option>$err</option>";
  while ($linha=mysql_fetch_array($sql)):
    $porto=$linha['PORTO'];
    echo "<option value='$porto'>$porto</option>\n";
  endwhile;
?>
</select>

Comentários

Postagens mais visitadas