How to list multiple columns using Inner Join and left Join?

Asked

Viewed 501 times

2

How can I get data from two tables?

Example.

inserir a descrição da imagem aqui

insira o código aqui

the fields

`assunto,nomeremetente,cpfremetente,observacao` da tabela **protocolos** 

and the datacriacao table protocolo_documents

is of the protocolo_documents is dataformat(datacriacao,'%d/%m/%Y') as datacriacao thus the initial query .

$Query ="SELECT 
                        dataformat(datacriacao,'%d/%m/%Y') as datacriacao,
                         assunto,nomeremetente,cpfremetente,observacao 
                           FROM protocolos 
                               ORDER BY formatted_date DESC"; 
  • 5
  • @rray You are very fast today :p

  • @rray wants to get only the protocolo_documents table creation and the rest of the protocols table.

  • @allanaraujo, what relation between the tables?

  • I want to take all the data subject, forwarder, forwarder, observation and bring up the dating of protocolo_documents

1 answer

1

You need to specify the relationship between the two tables in the clause ON, as 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, see how to use here.

Browser other questions tagged

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