简体   繁体   中英

What's the difference between this WHERE clause and this Join?

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

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM