← inner_join operator page · join/inner_join/nary/manual_ex_5
pandas ✅ · DuckDB ✅
three statements: the last joins DS_4 with two aliased expressions, IBSC and IBSD, renamed so that Id_1 is their only common identifier.
Inner Join, Example 5, with the page's result: "The contents of inner_join are ideally determined stepwise".
five data points on the key Id_1, with the Me_3 of IBSD (null, and 50 for Id_1 = 3); only DS_r is compared.
Me_3 is in both IBSC and IBSD, and stripping the prefixes would give two Me_3, an error by the Behaviour section, so the script adds drop IBSC#Me_3 (null everywhere); ds_5.json declares Me_2 an Identifier, but the result has Me_21 and Me_22 as Measures, so it is loaded as a Measure. The input files also name their data set DS_r, a slip with no effect: they are loaded as DS_5 and DS_6.
IBSC := inner_join(DS_5, DS_6[sub Id_4 = "c"] as CI); IBSD := inner_join(DS_5, DS_6[sub Id_4 = "d"] as DI); DS_r := inner_join ( DS_4, IBSC[rename Id_2 to Id_21, Id_3 to Id_31, Me_2 to Me_21] as IBSC, IBSD[rename Id_2 to Id_22, Id_3 to Id_32, Me_2 to Me_22] as IBSD drop IBSC#Me_3 );
| Id_1 | Me_1 |
|---|---|
| 1 | 200 |
| 2 | 300 |
| 3 | 100 |
{
"datasets": [
{
"name": "DS_4",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "Me_1", "type": "Integer", "role": "Measure", "nullable": true}
]
}
]
}
| Id_2 | Id_3 | Me_2 |
|---|---|---|
| 10 | S11 | 12345678 |
| 20 | S2 | 87654321 |
| 30 | S121 | 18273645 |
{
"datasets": [
{
"name": "DS_5",
"DataStructure": [
{"name": "Id_2", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "Id_3", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Me_2", "type": "Integer", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_2 | Id_4 | Me_3 |
|---|---|---|---|
| 1 | 30 | c | |
| 1 | 10 | d | |
| 2 | 30 | c | |
| 2 | 20 | c | |
| 2 | 10 | d | |
| 3 | 30 | c | |
| 3 | 10 | d | 50 |
| 3 | 20 | d | 50 |
{
"datasets": [
{
"name": "DS_6",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "Id_2", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "Id_4", "type": "String", "role": "Identifier", "nullable": false},
{"name": "Me_3", "type": "Integer", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_21 | Id_22 | Me_1 | Id_31 | Me_21 | Id_32 | Me_22 | Me_3 |
|---|---|---|---|---|---|---|---|---|
| 1 | 30 | 10 | 200 | S121 | 18273645 | S11 | 12345678 | |
| 2 | 30 | 10 | 300 | S121 | 18273645 | S11 | 12345678 | |
| 2 | 20 | 10 | 300 | S2 | 87654321 | S11 | 12345678 | |
| 3 | 30 | 10 | 100 | S121 | 18273645 | S11 | 12345678 | 50 |
| 3 | 30 | 20 | 100 | S121 | 18273645 | S2 | 87654321 | 50 |
{
"datasets": [
{
"name": "DS_r",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier"},
{"name": "Id_21", "type": "Integer", "role": "Identifier"},
{"name": "Id_22", "type": "Integer", "role": "Identifier"},
{"name": "Me_1", "type": "Integer", "role": "Measure"},
{"name": "Id_31", "type": "String", "role": "Identifier"},
{"name": "Me_21", "type": "Integer", "role": "Measure"},
{"name": "Id_32", "type": "String", "role": "Identifier"},
{"name": "Me_22", "type": "Integer", "role": "Measure"},
{"name": "Me_3", "type": "Integer", "role": "Measure"}
]
}
]
}