• 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
    ARCAD Software

    Embrace VS Code for IBM i Development

    The IBM i development landscape is evolving with modern tools that enhance efficiency and collaboration. Ready to make the move to VS Code for IBM i?

    Join us for this webinar where we’ll showcase how VS Code can serve as a powerful editor for native IBM i code and explore the essential extensions that make it possible.

    In this session, you’ll discover:

    • How ARCAD’s integration with VS Code provides deep metadata insights, allowing developers to assess the impact of their changes upfront.
    • The role of Git in enabling seamless collaboration between developers using tools like SEU, RDi, and VS Code.
    • Powerful extensions for code quality, security, impact analysis, smart build, and automated RPG conversion to Free Form.
    • How non-IBM i developers can now contribute to IBM i projects without prior knowledge of its specifics, while ensuring full control over their changes.

    The future of IBM i development is here. Let ARCAD be your guide!

    Watch Now

    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 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
  • Q&A With IBM’s New GM Of Power, Hillery Hunter
  • When IBM i Skills Become A Resilience Risk
  • Guru: Load A Varying-Dimension Array With One SQL Fetch
  • You Have To Speak IBM’s Language If You Want To Be Heard
  • Raz-Lee Revs iSecurity Suite With 2026 Updates

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