Relationship of two tables

1

Well, I have two tables and I need to relate 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 clients table ... I am having a very difficult time ...

    
asked by anonymous 30.08.2016 / 22:05

1 answer

3

In the example below, I created an 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 substitute the field names to use.

example: c.nome_empresa, c.empresa_tel

    
30.08.2016 / 22:09