Skip to content Skip to sidebar Skip to footer

Difference Of "from A Left Join B" Vs. "from A, B"

Do the queries do the same? What is the standard? Will I lose performance if I change one of these ways of write the query? Query 1 SELECT a.*, b.id AS b_id FROM table_a AS

Solution 1:

They return different results.

A LEFT JOIN statement will return rows even if there is no associated records in table_b that match table_a id. So it will return all rows in table_a, paired with EITHER a matching row in table_a OR a blank/null table_b row (if for that row in table_a there isn't any matching row in table_b).

The second query is a shortcut for an INNER JOIN. This query will ONLY exclusively return rows that match the condition a.id = b.id. The second query can also be written as:

SELECT a.*, b.id AS b_id
FROM table_a a
INNER JOIN table_b b 
ON a.id = b.id

To answer your performance question, please see the answers on a related SO thread here.

Post a Comment for "Difference Of "from A Left Join B" Vs. "from A, B""