17.5. JOINs by Function Calls

JOINs can also be done inside functions that relate columns from one or more tables in their parameters. This is easier to explain with an actual example, from John Botibol of Deverill plc in Dorset, U.K. His problem was how to “flatten” legacy data stored in a flat file database into a relational format for a data warehouse. The data included a vast amount of demographic information on people, related to their subjects of interest. The subjects of interest were selected from a list; some subjects required just one answer, and others allowed multiple selections.

The problem was that the data for multiple selections was stored as a string with a one or a zero in positional places to indicate “interested” or “not ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.