Relatedd and two tables

Asked

Viewed 29 times

1

Guys, I have two tables and I need to connect them. I’m doing it this way:

SELECT lancamentos .* FROM lancamentos
  INNER JOIN clientes ON lancamentos.cliente_id = clientes.id
  ORDER BY clientes.nome ASC

But I need to bring the name of the company that is in the client table ... I’m having a hard time with this ...

1 answer

3


In the example below, I created a alias for each table.

SELECT l.*, c.* 
FROM lancamentos as l
JOIN clientes as c ON c.id = l.cliente_id
ORDER BY c.nome ASC

It is not good practice to use asterisks, so replace with the name of the fields you are using.

example: c.nome_empresa, c.empresa_tel

  • Thanks Allan, once again you help me .. Thanks !!

Browser other questions tagged

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