Reputation: 1587
What's the difference between this:
SELECT *
FROM table1, table2
WHERE table1.primary_id = table2.primary_id
And this:
SELECT *
FROM table1
FULL JOIN table2 ON table1.primary_id = table2.primary_id
Upvotes: 0
Views: 315
Reputation: 1456
The FULL JOIN
keyword returns all the rows from the table1
, and all the rows from table2
. If there are rows in table1
that do not have matches in table2
, or if there are rows in table2
that do not have matches in table1
, those rows will be listed as well, filled with nulls
.
The first query will only return results where table1
has a match on table2
(primaryId
). It is the equivalent of an INNER JOIN
.
Upvotes: 0
Reputation: 70678
The first query is an implicit INNER JOIN
, you should always use the explicit syntax. In that case, the query will return the records that are in table1 and in table2. The second query will return all the records of both tables, showing NULL
if there are no match on the other.
Upvotes: 4