How to do a multi-table query in PHP? [closed]

-1
$sele = "SELECT * FROM videos WHERE video_titulo LIKE '%$name%' OR video_chaves LIKE '%$name%'";

$query = "SELECT * FROM usuarios WHERE n_nome LIKE '%$name%' OR n_usuario LIKE '%$name%'";

How to search the two 2 tables in one query? So:

$search="SELECT * FROM tabela1, tabela2....."
    
asked by anonymous 28.08.2015 / 15:37

1 answer

5

You can use the command UNION .

SELECT * FROM TABELA_1
UNION
SELECT * FROM TABELA_2

ATTENTION

But to use this command the tables must have the same number of columns!

OBJECTIVE

"Hi, but you do not have it, so what now?"

SOLUTION

Put in the SELECT only the fields you will need to query, the same amount being the same.

EXAMPLE

SELECT ID, NOME AS RESULTADO FROM TABELA_1
UNION
SELECT ID, DESCRICAO AS RESULTADO FROM TABELA_2
    
28.08.2015 / 16:01