What will be the opposite of inner join? For a table table Person (int PersonId, varchar PersoName, int AddrId)
, I want to know the rows in Person with bad AddrId
which don't have a row in the Address
table.
If you consider an inner join as the rows of two tables that meet a certain condition, then the opposite would be the rows in either table that don't.
The opposite of an INNER JOIN is an OUTER JOIN and it comes in two flavors: LEFT and RIGHT depending on which side of of the JOIN you want to "outer"
There are four main types of joins: inner join, full outer join, left outer join and right outer join. The major difference between inner and outer joins is that inner joins result in the intersection of two tables, whereas outer joins result in the union of two tables.
Different Types of SQL JOINs Here are the different types of the JOINs in SQL: (INNER) JOIN : Returns records that have matching values in both tables. LEFT (OUTER) JOIN : Returns all records from the left table, and the matched records from the right table.
What will be the opposite of inner join?
An OUTER join, which can be of three options:
This is a good visual representation of JOINs
I want to know the rows in Person with bad AddrId which don't have a row in the Address table.
SELECT p.* FROM PERSON p LEFT JOIN ADDRESS a ON a.addrid = p.addrid WHERE a.addrid IS NULL
SELECT p.* FROM PERSON p WHERE NOT EXISTS(SELECT NULL FROM ADDRESS a WHERE a.addrid = p.addrid)
SELECT p.* FROM PERSON p WHERE p.addrid NOT IN (SELECT a.addrid FROM ADDRESS a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With