How to list multiple columns using Inner Join and left join? [duplicate]

2

How can I get data from two tables?

Example.

thefields

'assunto,nomeremetente,cpfremetente,observacao'databela**protocolos**

anddatacriacaoofthedocument_documenttable

isofdocument_documentisdataformat(datacriacao,'%d/%m/%Y')asdatacriacaothusgettingtheinitialquery.

$Query="SELECT 
                        dataformat(datacriacao,'%d/%m/%Y') as datacriacao,
                         assunto,nomeremetente,cpfremetente,observacao 
                           FROM protocolos 
                               ORDER BY formatted_date DESC"; 
    
asked by anonymous 10.10.2016 / 19:51

1 answer

1

You need to specify the relationship between the two tables in the ON clause, as in the example below

SELECT dataformat(pd.datacriacao,'%d/%m/%Y') as datacriacao, p.*
FROM protocolos p
join protocolo_Documentos pd
on pd.protocolo = p.protocolo -- aqui tem que ser a relação entre as duas tabelas
ORDER BY formatted_date DESC

Regarding the use of JOIN or LEFT JOIN, here's how to use

10.10.2016 / 20:13