• 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
    Midrange Dynamics North America

    With MDRapid, you can drastically reduce application downtime from hours to minutes. Deploying database changes quickly, even for multi-million and multi-billion record files, MDRapid is easy to integrate into day-to-day operations, allowing change and innovation to be continuous while reducing major business risks.

    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

    Drummond Unveils AS2 Certificates Notes/Domino: Less Platform Talk, More Programming Action

    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

  • 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
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

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