edc_country
),
ed centers (edc_id
) and courses (crs_id
)
that are currently being offered (ie, for which there are sections).
in ascending order.
Solution.
SELECT edc_country, edc_id, crs_id FROM Ed_Center NATURAL JOIN Section ORDER BY edc_country, edc_id, crs_id;
This is plausible, but some ed centers might not be listed! This would happen if the there are no courses currently being taught at a location.
New Problem. Produce results as before, but include all ed centers, even if no courses are currently being taught.
An outer join causes all records (from either the left table, the right table, or both tables as speficied) to be used, and NULLs will be placed in all fields where there was no joined record.
Solution.
SELECT edc_country, edc_id, crs_id
FROM Ed_Center NATURAL LEFT OUTER JOIN Section
ORDER BY edc_country, edc_id, crs_id;
These results will show all ed centers. Those that aren't currently
teaching courses will have a NULL for the course.
FROM t1 NATURAL {LEFT | RIGHT | FULL} OUTER JOIN t2 FROM t1 {LEFT | RIGHT | FULL} OUTER JOIN t2 ON c1=c2 FROM t1 {LEFT | RIGHT | FULL} OUTER JOIN t2 USING (c,...)
c1 *= c2
, c1 =* c2
, and c1 *=* c2
.
Oracle uses the following syntax
c1 = c2 (+)
, c1 (+) = c2
, and c1 (+) = c2 (+)
,
confusingly putting the "(+)" on the opposite side of where the additional records
will be generated. Avoid these old, non-standard operators -
these database systems now also accept the standard outer join syntax in the
FROM clause.