Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symmetric difference (OuterJoin) #30

Closed
iRon7 opened this issue Apr 24, 2022 · 1 comment
Closed

Symmetric difference (OuterJoin) #30

iRon7 opened this issue Apr 24, 2022 · 1 comment

Comments

@iRon7
Copy link
Owner

iRon7 commented Apr 24, 2022

Getting everything that is unrelated as e.g.: Windows Powershell: How to compare two CSV files and output the rows that are just in either of the file but not in both appears to have a quite common use.
Meaning a FullJoin excluding all the objects in the InnerJoin.

@iRon7
Copy link
Owner Author

iRon7 commented Apr 25, 2022

Implemented OuterJoin:

$Csv1 = ConvertFrom-Csv @'
name,surname,height,city,county,state,zipCode
John,Doe,120,jefferson,Riverside,NJ,8075
Jack,Yan,220,Phila,Riverside,PA,9119
Jill,Fan,120,jefferson,Riverside,NJ,8075
Steve,Tan,220,Phila,Riverside,PA,9119
Alpha,Fan,120,jefferson,Riverside,NJ,8075
'@

$Csv2 = ConvertFrom-Csv @'
name,surname,height,city,county,state,zipCode
John,Doe,120,jefferson,Riverside,NJ,8075
Jack,Yan,220,Phila,Riverside,PA,9119
Jill,Fan,120,jefferson,Riverside,NJ,8075
Steve,Tan,220,Phila,Riverside,PA,9119
Bravo,Tan,220,Phila,Riverside,PA,9119
'@

$Csv1 |OuterJoin $Csv2 |ConvertTo-Csv
name,surname,height,city,county,state,zipCode
Alpha,Fan,120,jefferson,Riverside,NJ,8075
Bravo,Tan,220,Phila,Riverside,PA,9119

More specific:

PS C:\> $dataset1
A B    XY    ZY
- -    --    --
1 val1 foo1  bar1
2 val2 foo2  bar2
3 val3 foo3  bar3
4 val4 foo4  bar4
4 val4 foo4a bar4a
5 val5 foo5  bar5
6 val6 foo6  bar6

PS C:\>  $dataset2
A B    ABC   GH
- -    ---   --
3 val3 foo3  bar3
4 val4 foo4  bar4
5 val5 foo5  bar5
5 val5 foo5a bar5a
6 val6 foo6  bar6
7 val7 foo7  bar7
8 val8 foo8  bar8

PS C:\> $Dataset1 |OuterJoin $Dataset2 -on a,b
A B    XY   ZY   ABC  GH
- -    --   --   ---  --
1 val1 foo1 bar1
2 val2 foo2 bar2
7 val7           foo7 bar7
8 val8           foo8 bar8'

OuterJoin with two value arrays:

1..5 |OuterJoin @(3..7)
1
2
7
8

Note: do not confuse the OuterJoin with the SQL Full Outer Join which is in fact similar to the FullJoin type.

@iRon7 iRon7 changed the title Asymmetric difference (OuterJoin) Symmetric difference (OuterJoin) Apr 26, 2022
@iRon7 iRon7 closed this as completed Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant