INTERSECT ALL, EXCEPT ALL, and the arithmetic of fractions

SQL’s INTERSECT ALL and EXCEPT ALL operators rarely get attention, but they elegantly solve a classic math problem. The problem is computing the greatest common divisor (GCD) and least common multiple (LCM) of two integers, using the prime factors of those integers. In this post we show how to do this using intersect and except, Morel’s equivalent of INTERSECT ALL and EXCEPT ALL.