• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Non-Equal (Theta) Joins

    October 17, 2012 Ted Holt

    In George Orwell’s novel Animal Farm, all animals were declared to be equal. However, that was not the case. By the end of the book, some were “more equal than others.” You might think that all joins are equal, but you would be wrong. Unequal joins have their applications, too.

    The equijoin is the norm in business. A customer number in a table (file) of invoices matches (equals) a customer number in a customer master table. But it is also possible to join on non-matching conditions such as not equal, greater than, less than, greater than or equal to, less than or equal to. Such a join is called a theta join.

    With one exception, theta joins are not terribly useful. I rarely use them. The one exception is joining on ranges of values.

    For instance, assume you work for a company that uses a 445 accounting system. Each quarter of a year consists of two four-week periods and one five-week period. You might have a table that looks like this:




    Year

    Year

    Period

    Beginning Date

    Ending Date

    Quarter

    2011

    12

    2011-11-27

    2011-01-31

    4

    2012

    1

    2012-01-01

    2012-01-28

    1

    2012

    2

    2012-01-29

    2012-02-25

    1

    2012

    3

    2012-02-26

    2012-03-31

    1

    2012

    4

    2012-04-01

    2012-04-28

    2

    You may also have a table of shipments.




    Shipment

    Shipment

    Date

    Item

    Price

    Quantity

    1015

    2012-01-20

    AB101

    2.00

    2

    1016

    2012-01-27

    BZ873

    4.50

    1

    1017

    2012-01-30

    DL297

    1.00

    3

    1018

    2012-02-03

    AB202

    1.25

    2

    To report sales by period or quarter, or for a period or quarter, requires you to join the files, but you can’t do that with an equijoin. Instead, use BETWEEN.

    select per.year, per.period,
           sum(s.quantity) as Qty,
           sum(s.quantity * s.price) as Amount
      from shipments as s
      join accountingperiods as per
        on s.date between per.begindate and per.enddate
     group by per.year, per.period
     order by per.year, per.period
    

    The output looks like this:




    Year

    Year

    Period

    Qty

    Amount

    2012

    1

    3

    8.50

    2012

    2

    5

    5.50

    I’ve no doubt that there are other uses for theta joins that I’ve never thought of. I still have so much to learn.

    RELATED STORIES

    Updating Through a Join with SQL, Take Two

    Don’t Let Users Wreck Their Joins

    Updating through a Join with SQL



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    VISUAL LANSA 16 WEBINAR

    Trying to balance stability and agility in your IBM i environment?

    Join this webinar and explore Visual LANSA 16 – our enhanced professional low-code platform designed to help organizations running on IBM i evolve seamlessly for what’s next.

    🎙️VISUAL LANSA 16 WEBINAR

    Break Monolithic IBM i Applications and Unlock New Value

    Explore modernization without rewriting. Decouple monolithic applications and extend their value through integration with modern services, web frameworks, and cloud technologies.

    🗓️ July 10, 2025

    ⏰ 9 AM – 10 AM CDT (4 PM to 5 PM CEST)

    See the webinar schedule in your time zone

    Register to join the webinar now

    What to Expect

    • Get to know Visual LANSA 16, its core features, latest enhancements, and use cases
    • Understand how you can transition to a MACH-aligned architecture to enable faster innovation
    • Discover native REST APIs, WebView2 support, cloud-ready Azure licensing, and more to help transform and scale your IBM i applications

    Read more about V16 here.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Vision Solutions:  Free White Paper: An Introduction to HA for Power Systems Running IBM i
    HiT Software:  Download "Five Reasons for Change Data Capture in the Cloud"
    ITJ Bookstore:  Bookstore BLOWOUT!! Up to 50% off all titles! Everything must go! Shop NOW

    IT Jungle Store Top Book Picks

    Bookstore Blowout! Up to 50% off all titles!

    The iSeries Express Web Implementer's Guide: Save 50%, Sale Price $29.50
    The iSeries Pocket Database Guide: Save 50%, Sale Price $29.50
    Easy Steps to Internet Programming for the System i: Save 50%, Sale Price $24.97
    The iSeries Pocket WebFacing Primer: Save 50%, Sale Price $19.50
    Migrating to WebSphere Express for iSeries: Save 50%, Sale Price $24.50
    Getting Started with WebSphere Express for iSeries: Save 50%, Sale Price $24.50
    The All-Everything Operating System: Save 50%, Sale Price $17.50
    The Best Joomla! Tutorial Ever!: Save 50%, Sale Price $9.98

    Overland Launches LTO 6 Tape Drives Database Modernization: A Matter of Survival for IBM i ISVs

    Leave a Reply Cancel reply

Volume 12, Number 25 -- October 17, 2012
THIS ISSUE SPONSORED BY:

WorksRight Software
ProData Computer Services
American Top Tools

Table of Contents

  • What’s That Name?
  • Non-Equal (Theta) Joins
  • Admin Alert: One Year Out–Preparing For Your Next IBM i Upgrade, Part 2

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle