List two mysql Pdo tables

Asked

Viewed 337 times

0

$catalog = $dbh->prepare("SELECT * FROM catalogo WHERE ativo = 2 ORDER BY catalogo_view DESC LIMIT 0,5");
$catalog->execute();

I want to search between two tables, as I do?

  • 1

    JOIN? there is correspondence between the tables?

  • The two tables are interconnected?

  • 1

    If the tables have a common reference, you can use Join. Select * from tabela1 join tabela 2
on tabela1.campo = tabela2.campo

1 answer

0

Try using UNION, but remember that in UNION the columns of the query have to have the same amount.

SELECT cliente_codigo, cliente_nome FROM cliente
UNION SELECT funcionario_codigo, funcionario_nome FROM funcionario
WHERE ativo = 2

Browser other questions tagged

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