Back to Examples
- Binding patterns
- Typed binding pattern
- Wildcard binding pattern
- List binding patterns
- Rest binding pattern in list binding pattern
- Mapping binding pattern
- Rest binding pattern in mapping binding pattern
- Error binding pattern
- Rest binding pattern in error binding pattern
- Single use of typed binding patterns
- Single use of typed binding patterns with on fail clause
- Iterative use of typed binding patterns
- List binding pattern in match statement
- Mapping binding pattern in match statement
- Error binding pattern in match statement
- Query expressions
- Sort iterable objects
- Let clause
- Limit clause
- Join iterable objects
- Outer Join clause
- Query tables
- Create tables with a query
- Create maps with a query
- Create streams with a query
- On conflict clause
- Advanced conflict handling
- Iterate over XML with a query
- Nested query expressions
- Destructure records using a query
- Querying streams
- Aggregation
- JSON type
- Access JSON elements
- Access optional JSON elements
- Match statement with maps
- Convert from user-defined type to JSON
- Convert from table and XML to JSON
- Convert from JSON to user-defined type
- Cast JSON to user-defined type
- Resource method typing
- JSON numbers
- JSON to record
- JSON to record with projection
- JSONPath expressions
- Asynchronous function calls
- Named workers
- Sequence diagrams
- Wait for workers
- Strands
- Named worker return values
- Alternate wait
- Multiple wait
- Named workers and futures
- Inter-worker message passing
- Alternate receive
- Multiple receive
- Conditional send
- Inter-worker failure propagation
- Named worker with on fail clause
- Synchronize message passing
- Asynchronize message passing
- Flush
- Fork
Outer join clause
The outer join
clause performs a left outer equijoin. This join returns each element of the first collection regardless of whether it has any matching elements in the second collection. For the values for which there is no matching value on the second collection, the resulting value will contain nil
.
import ballerina/io;
type Department record {|
int id;
string name;
|};
type Person record {|
int id;
string fname;
string lname;
|};
type DeptPerson record {|
string fname;
string? dept;
|};
public function main() {
Person p1 = {id: 1, fname: "Alex", lname: "George"};
Person p2 = {id: 2, fname: "John", lname: "Fonseka"};
Person p3 = {id: 3, fname: "Ted", lname: "Perera"};
Department d1 = {id: 1, name:"HR"};
Department d2 = {id: 2, name:"Operations"};
Person[] personList = [p1, p2, p3];
Department[] deptList = [d1, d2];
DeptPerson[] deptPersonList =
from Person person in personList
// The `outer join` clause performs a left outer equijoin.
// For the records for which there is no matching record
// on the `deptList`, the resulting record will contain `nil` fields.
outer join var dept in deptList
on person.id equals dept?.id
select {
fname : person.fname,
dept : dept?.name
};
io:println(deptPersonList);
}
$ bal run outer_join_clause.bal[{"fname":"Alex","dept":"HR"},{"fname":"John","dept":"Operations"},{"fname":"Ted","dept":null}]
PreviousJoin iterable objects
NextQuery tables