outer join in MS Excel

后端 未结 3 2065
野趣味
野趣味 2021-01-19 10:15

do you have an idea how to join two tables with the outer join ? Know to do this in SQL, but I need Excel now.

I have a list of all employees in one column I have a

3条回答
  •  佛祖请我去吃肉
    2021-01-19 10:39

    This method does copy and pasting, filtering, and sorting to accomplish an outer join in Excel and good for just one offs. The idea is to use a VLOOKUP to find all matching records from the left to the right tables and right to the left tables. [Adding another record to table 2 to show outer join]

    Table 1

    Fernando
    Hector
    Vivian
    Ivan
    

    Table 2

    Fernando, task A, 5 hours
    Vivian, task B, 8 hours
    Thomas, task A, 5 hours
    

    Copy both tables into one table where table 1 will take up the first left columns and first rows and table 2 will take up the last right columns and last rows (The headers should be row 1 for both tables). Create a VLOOKUP function for the next two columns to find matching keys from the left to right tables and right to left tables.

    Table 3

    Name     Name     Task    Hours   Match 1                  Match 2
    Fernando                          =VLOOKUP(A2,B:B,1,FALSE) =VLOOKUP(B2,A:A,1,FALSE)
    Hector                            =VLOOKUP(A3,B:B,1,FALSE) =VLOOKUP(B3,A:A,1,FALSE)
    Vivian                            =VLOOKUP(A4,B:B,1,FALSE) =VLOOKUP(B4,A:A,1,FALSE)
    Ivan                              =VLOOKUP(A5,B:B,1,FALSE) =VLOOKUP(B5,A:A,1,FALSE)
             Fernando task A  5 hours =VLOOKUP(A6,B:B,1,FALSE) =VLOOKUP(B6,A:A,1,FALSE)
             Vivian   task B  8 hours =VLOOKUP(A7,B:B,1,FALSE) =VLOOKUP(B7,A:A,1,FALSE)
             Thomas   task B  8 hours =VLOOKUP(A8,B:B,1,FALSE) =VLOOKUP(B8,A:A,1,FALSE)
    

    Table 3 Result

    Name     Name     Task    Hours   Match 1  Match 2
    Fernando                          Fernando N/A
    Hector                            N/A      N/A
    Vivian                            Vivian   N/A
    Ivan                              N/A      N/A
             Fernando task A  5 hours N/A      Fernando
             Vivian   task B  8 hours N/A      Vivian
             Thomas   task B  8 hours N/A      N/A
    

    NOTE: For large data sets, the next step will take a very long time because of the VLOOKUP calculation that happens. Copy and paste over columns for match 1 and match 2 columns as values so that VLOOKUP doesn't recalculate during filtering.

    Filter on Match 1 and Match 2 to only see all N/A results. Copy the main data to another sheet with headers.

    Name     Name     Task    Hours   Match 1  Match 2
    Hector                            N/A      N/A
    Ivan                              N/A      N/A
             Thomas   task B  8 hours N/A      N/A
    

    Filter on Match 1 and Match 2 to not see N/A results. Sort on keys for both, so that when copy and pasting everything matches. Copy and paste Table 1 data into the new sheet below previously pasted data first. Then copy and paste Table 2 data to the right of the Table 1 data that was just pasted.

    Name     Name     Task    Hours   Match 1  Match 2
    Fernando                          Fernando N/A
    Vivian                            Vivian   N/A
             Fernando task A  5 hours N/A      Fernando
             Vivian   task B  8 hours N/A      Vivian
    

    The result is below and you can delete, sort, whatever to the outer joined data.

    Name     Name     Task    Hours
    Hector
    Ivan
             Thomas   task B  8 hours
    Fernando Fernando task A  5 hours
    Vivian   Vivian   task B  8 hours
    

提交回复
热议问题