Left join
Returns a table with all rows from the left table and matched rows from the right table. The returned table columns are the joined columns for left and right table.
The match is performed by comparing the key-columns for equality and when no matching row is found, the relevant columns are left as none.
Left-join is done via lj or ljf functions. Both perfom left-join, but latter fills left-hand-side nones with right-hand-side values.
Example
Include required headers and define the columns:
#include <cpptables/table.hh>
#include <iostream>
using namespace tables;
using namespace std;
struct c0{ constexpr static string_view name = "Col0"; };
struct c1{ constexpr static string_view name = "Col1"; };
struct c2{ constexpr static string_view name = "Col2"; };
Construct left table:
using table0_t = table<
pair<c0,string_view>,
pair<c1,int>
>;
const table0_t t0(
{"abc", "def", "ghi", "abc", "def", "ghi"},
{100,200,300,400,500,600}
);
cout << "t0:\n" << t0 << "\n";
Construct right table:
using table1_t = table<
pair<c0,string_view>,
pair<c2,unsigned>
>;
const table1_t t1(
{"abc", "def", "foo"},
{1,2,3}
);
cout << "t1:\n" << t1 << "\n";
Do a left join using c0
as key-column:
const auto t_lj = t0.lj( t1.key_by<c0>() );
cout << "t_lj:\n" << t_lj << "\n";
Output should be:
t0: Col0 Col1 --------- abc 100 def 200 ghi 300 abc 400 def 500 ghi 600 t1: Col0 Col2 --------- abc 1 def 2 foo 3 t_lj: Col0 Col1 Col2 -------------- abc 100 1 def 200 2 ghi 300 none abc 400 1 def 500 2 ghi 600 none