• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Don’t Let Users Wreck Their Joins

    January 26, 2011 Ted Holt

    You’re swamped with work, and here comes Harold in Accounts Receivable yet again for help with some query he threw together that doesn’t work correctly. Harold’s not a bad guy–his wife, his kids, and his dog adore him. He just doesn’t understand computer stuff. Here’s a way you can help him help you.

    Harold’s problem is that he doesn’t understand how to join files properly. What you need is a way to store join field information on the system. That is, you need a way to store the fact that file A and file B join over field C and field D so Harold doesn’t have to know that information. And here is that way.

    Let’s say you have four physical files (or tables, in database jargon) with related data.

    • Sales order headers
    • Sales order details
    • The customers to whom you sell
    • The items you sell

    Furthermore:

    • One sales order header relates to one or more sales order details by a common sales order number
    • One sales order header relates to one customer by a common company number and customer number
    • One sales order detail relates to one item by a common item number

    This makes perfect sense to you, but not to Harold. To help him, define the joins for him, like this:

    create view slsordv1 as
    (select 
       oh.ORDERNO,
       oh.CUSTPO, 
       oh.STATUS as OrderStat, 
       oh.ORDERDATE,
       oh.SHIPDATE,
       od.LINENO,
       od.ITEMNO, 
       it.DESCRIP as ItemDesc,
       it.CLASS as ItemClass,
       it.COST as BaseCost,
       it.PRICE as BasePrice,
       it.MINORDQTY, 
       it.MAKEBUY, 
       it.WEIGHT, 
       it.DISCOUNT,
       it.VMI, 
       it.ACTIVE, 
       od.QTYORDERED, 
       od.QTYSHIPPED, 
       od.PRICE,
       oh.COMPANYNO, 
       oh.CUSTOMERNO, 
       cus.CUSNAM,
       cus.BILLSTREET, 
       cus.BILLCITY, 
       cus.BILLSTATE, 
       cus.BILLZIP, 
       cus.SHIPSTREET, 
       cus.SHIPCITY, 
       cus.SHIPSTATE, 
       cus.SHIPZIP, 
       cus.TYPE as CusType
    from salesordh as oh
    left outer join salesordd as od
    using (orderno)
    left outer join customers as cus
    using (companyno, customerno)
    left outer join items as it
    using (itemno)
    )
    

    Create view builds an unkeyed logical file that Harold can query as he would a physical file. Harold operates under the illusion that all of that data is stored in one big database file, and that means no joins. Harold can select fields (columns), select records (rows), sort, etc., and you can work on something more challenging.

    Have some compassion. Don’t make Harold join physical files.

    RELATED STORIES

    Subqueries vs. Joins

    Redundant Join Criteria: Good or Bad Idea?

    A Database Union is Not a Join

    Missing In Action: The Full Outer Join



                         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
    FalconStor

    Simplify Secure Offsite Data Protection for IBM Power with FalconStor Habanero™

    IBM i teams are under growing pressure to ensure data is protected, recoverable, and compliant—without adding complexity or disrupting stable environments.

    FalconStor Habanero™ provides secure, fully managed offsite data protection purpose-built for IBM Power. It integrates directly with existing IBM i backup tools and processes, enabling reliable offsite copies without new infrastructure, workflow changes, or added operational overhead.

    By delivering and managing the service end-to-end, FalconStor helps organizations strengthen cyber resilience, improve disaster recovery readiness, and meet compliance requirements with confidence. Offsite copies are securely maintained and available when needed, supporting recovery, audits, and business continuity.

    FalconStor Habanero offers a straightforward way to modernize offsite data protection for IBM i: focused on simplicity, reliability, and resilience.

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    SEQUEL Software:  FREE Webinar. SEQUEL: The Only Data Access Tool. Jan. 26
    ProData Computer Services:  We've added MORE! DBU 9.0 Now Available!
    Four Hundred Monitor Calendar:  Latest info on national conferences, local events, & Webinars

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    A Reusable Routine for Doubly-Linked Lists, Part 2 Why Can’t I Move System Memory Between Partition?

    Leave a Reply Cancel reply

Volume 11, Number 4 -- January 26, 2011
THIS ISSUE SPONSORED BY:

ProData Computer Services
WorksRight Software
System i Developer

Table of Contents

  • A Reusable Routine for Doubly-Linked Lists, Part 2
  • Don’t Let Users Wreck Their Joins
  • Why Can’t I Move System Memory Between Partition?

Content archive

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

Recent Posts

  • Big Blue Unveils Bob Premium Pack For IBM i
  • Midrange Dynamics Sees Solid Git Adoption On IBM i
  • Guru: SQL Sequences In RPG Let Db2 Handle The Counting
  • From Green Screens To Smart Factories: Explaining DevOps To The Next Gen IBM i Developers
  • IBM i PTF Guide, Volume 28, Numbers 18 And 19
  • Big Blue Is Still Talking About Future Power Processors, Which Is Good
  • Who To Consult With On Your Cloud Strategy, And Who To Manage It
  • Guru: DateTime Rules Of Thumb
  • i-Rays Performance Analyzer Now Ready for Prime Time, Omniology Says
  • CNX Adds AI To Valence Development Tool

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