Use join to achieve intersection, union, difference, and complement effects

Keyword of sql set operation

      In sql, the calculation of sets is: union, difference, and intersection.
      Union: union, union all
      difference: EXISTS, not in, except
      intersection: InterSect
      But, not every database supports all of the above, and the keywords are not the same. Just like oracle, minus is used for difference. emmm ... so uncomfortable.

join can also be achieved

Insert picture description here
      To achieve this situation, inner join is enough.

Insert picture description here
      To achieve this, left join is enough.

Insert picture description here
      To achieve this, right join is enough.

Insert picture description here
      To achieve this situation:

select * 
from a left join b 
on a.id = b.id
where b.id is null

      
Insert picture description here
      To achieve this situation:

select * 
from a right join b 
on a.id = b.id
where a.id is null

      https://blog.csdn.net/weixin_42845682/article/details/105412597 There is a question in this article, you can practice it after reading it.

Published 48 original articles · Like 36 · Visits 130,000+

Guess you like

Origin blog.csdn.net/weixin_42845682/article/details/105414734