When is a good situation to use a full outer join?

后端 未结 7 1602
耶瑟儿~
耶瑟儿~ 2020-12-23 02:07

I\'m always discouraged from using one, but is there a circumstance when it\'s the best approach?

7条回答
  •  鱼传尺愫
    2020-12-23 02:35

    Just today I had to use Full Outer Join. It is handy in situations where you're comparing two tables. For example, the two tables I was comparing were from different systems so I wanted to get following information:

    1. Table A has any rows that are not in Table B
    2. Table B has any rows that are not in Table A
    3. Duplicates in either Table A or Table B
    4. For matching rows whether values are different (Example: The table A and Table B both have Acct# 12345, LoanID abc123, but Interest Rate or Loan Amount is different

    In addition, I created an additional field in SELECT statement that uses a CASE statement to 'comment' why I am flagging this row. Example: Interest Rate does not match / The Acct doesn't exist in System A, etc.

    Then saved it as a view. Now, I can use this view to either create a report and send it to users for data correction/entry or use it to pull specific population by 'comment' field I created using a CASE statement (example: all records with non-matching interest rates) in my stored procedure and automate correction, etc.

    If you want to see an example, let me know.

提交回复
热议问题