Our section pays a fuel subsidy to licensees known as BEUs. Each BEU
licensee has a unique licence_id.
> Peter,
> I've got an example of a FULL OUTER JOIN:
> There are two tables:
> the first table containes the amount of apples ;) a person should have
> the second table containes the amount of apples a person actually has
> received
> It's not a given that a person in the first table must exist in the second
> table and
> likewise, the other way round
> So I need all persons from table one AND all persons from the second
> table.
> This is the statement I used:
> ( KPN means Royal Dutch Apple Inc. ;)
> CREATE TABLE tmp_KPNmatch AS
> SELECT ifnull(tk1.speler, tk2.speler) AS
> speler,
> ifnull(tk1.uit_te_geven, 0) AS
> uit_te_geven,
> ifnull(tk2.uitgegeven, 0) AS
> uitgegeven,
> (ifnull(tk1.uit_te_geven, 0) - ifnull(tk2.uitgegeven, 0)) AS
> verschil
> FROM tmp_KPN1 tk1
> FULL OUTER
> JOIN tmp_KPN2 tk2 on tk1.speler = tk2.speler
> WITH location = (db01, db02, db03),
> structure = BTREE,
> key = ( speler );
> This works like a charm and I used it (just now) real-life...
> Dutch groeten,
> Mark Frenay
> > -----Oorspronkelijk bericht-----
> > Tim Ellis
> > Verzonden: donderdag 4 april 2002 11:47
> > Onderwerp: Re: The Outer Join Challenge
> > > >>That is the challenge. Can someone show a genuine use for the FULL
> > > >>JOIN. I need table specs, sql and a description of what the query is
> > > >>supposed to be showing. The main rule in this challenge is that you
> > > >>must really need to run this query. It is not sufficient to
> simply code
> > > >>up a FULL JOIN to show what it does.
> > I had a quick look through some old SQL and found this, which is a
> > genuine example, although it certainly isn't the only way of getting
> > the result (I strongly suspect it was done this way as much to show
> > the use of the full join as anything else) - it is, however fairly
> > small and self contained...
> > Table OT (in reality this table was a session table built up from a
> > number of queries, but for simplicity I'll show it as a base table
> > here...)
> > Fields Employee_no, Year_Week, Day_no, OT_Code, OT_Time
> > This table contains the amount of Overtime booked by an employee on a
> > particular day, held as Year_week and a Day Number where Saturday is
> > Day 1.
> > Create two temporary tables to add up the total amount of Week day and
> > Week end overtime
> > declare global temporary table session.sum_wd as
> > select employee_no,year_week,sum(ot_time) as "OT_WDAY"
> > from ot
> > where day_no > 2
> > and ot_code = 'P'
> > group by employee_no,year_week
> > on commit preserve rows with norecovery,structure=btree,
> > key = (year_week,employee_no);
> > declare global temporary table session.sum_we as
> > select employee_no,year_week,sum(ot_time) as "OT_Wend"
> > from ot
> > where day_no < 2 and ot_code = 'P'
> > group by employee_no,year_week
> > on commit preserve rows with norecovery,structure=btree,
> > key = (year_week,employee_no);
> > Then "Full Join" them into a table which will show the total amount of
> > weekday and/or weekend Overtime for any employee who has worked
> > either...
> > declare global temporary table session.sums as
> > select a.employee_no,a.year_week,ifnull(ot_wday,0) as "OT_WDAY",
> > ifnull(ot_wend,0) as "OT_WEND",b.employee_no as "EMP_NO",b.year_week
> > as
> > "YW"
> > from session.sum_wd a full join session.sum_we b
> > on a.employee_no = b.employee_no and
> > a.year_week = b.year_week
> > on commit preserve rows with norecovery,structure=btree
> > ,key=(year_week,employee_no);
> > Finally replace the "null" key values in this table from the "other"
> > set of values...
> > update session.sums
> > set year_week = yw, employee_no = emp_no
> > where year_week is null;
> > This table can now be used to drive reports / further queries