|
The LEFT JOIN clause is one of the joins that allows you to query data from two or more tables.
Suppose, you have two tables: T1 and T2, called the left and the right tables respectively.
The LEFT JOIN clause selects data starting from the left table (T1).
It compares each row in the left table with every row in the right table.
If two rows match, the LEFT JOIN combines columns of these two rows into a row and includes this row in the final result set.
In case a row from the left table does not have any matching row from the right table, the LEFT JOIN also combines the columns of the row from the left table with
The columns of the right table.
However, the columns from the right table will have NULL values.
In other words, the LEFT JOIN clause returns all rows from the left table ( T1) and matching rows or NULL values from the right table ( T2).
Returns all rows from the left table, and the matching rows from the right table
A cláusula LEFT JOIN é uma das junções que permite consultar dados de duas ou mais tabelas.
Suponha que você tenha duas tabelas: T1 e T2, chamadas de tabelas da esquerda e da direita, respectivamente.
A cláusula LEFT JOIN seleciona dados a partir da tabela à esquerda ( T1).
Ele compara cada linha da tabela da esquerda com todas as linhas da tabela da direita.
Se houver correspondência de duas linhas, o LEFT JOIN combina as colunas dessas duas linhas em uma linha e inclui essa linha no conjunto de resultados final.
Caso uma linha da tabela da esquerda não tenha nenhuma linha correspondente da tabela da direita, o LEFT JOIN também combina as colunas da linha da tabela da
esquerda com as colunas da tabela da direita.
No entanto, as colunas da tabela certa terão valores NULL.
Em outras palavras, a cláusula LEFT JOIN retorna todas as linhas da tabela da esquerda ( T1) e linhas correspondentes ou valores NULL da tabela da direita ( T2).
Retorna todas as linhas da tabela da esquerda e as linhas correspondentes da tabela da direita
The LEFT JOIN command returns all rows from the left table, and the matching rows from the right table.
The result is NULL from the right side, if there is no match.
O comando LEFT JOIN retorna todas as linhas da tabela esquerda e as linhas correspondentes da tabela direita.
O resultado é NULL do lado direito, se não houver correspondência.
The following SQL will select all customers, and any orders they might have:
O seguinte SQL selecionará todos os clientes e quaisquer pedidos que eles possam ter:
SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
|
Note:
The LEFT JOIN keyword returns all records from the left table (Customers), even if there are no matches in the right table (Orders).
Nota:
A palavra-chave LEFT JOIN retorna todos os registros da tabela da esquerda (Clientes), mesmo se não houver correspondências na tabela da direita (Pedidos).
Veja também:
|