SQL-J Language Reference
Page 39 of 121

LEFT OUTER JOIN

A LEFT OUTER JOIN is one of the JOIN operations that allow you to specify a join clause. It preserves the unmatched rows from the first (left) table, joining them with a NULL row in the shape of the second (right) table.

Syntax

TableExpression LEFT OUTER JOIN TableExpression
{
    ON booleanExpression |
    USING ( SimpleColumnName [ , SimpleColumnName]* )
}

The scope of expressions in either the ON or the USING clause includes the current tables and any tables in query blocks outer to the current SELECT. The ON clause can reference tables not being joined and does not have to reference either of the tables being joined (though typically it does). For additional differences between ON and USING clauses, see ResultSet and Performance Differences Between ON and USING.

LEFT OUTER JOIN Examples

--match cities to countries, showing even those
--countries that have no matching cities
SELECT country, city.getName()
FROM Countries LEFT OUTER JOIN Cities
USING (country_ISO_code)

-- show all Flights, including those without any seats_booked
SELECT Flights.flight_id, number_seats
FROM Flights
LEFT OUTER JOIN Segments_SeatBookings
ON Flights.flight_id = Segments_SeatBookings.flight_id

-- show multiple join
SELECT country, city.getName(), hotel_name, normal_rate
FROM COUNTRIES LEFT OUTER JOIN Cities
ON Countries.country_ISO_code=Cities.country_ISO_code
LEFT OUTER JOIN Hotels
ON Cities.city_id=Hotels.city_id