• 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:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) 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 ReplyCancel 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

  • Power Systems Has A Great Quarter; System Z, Not So Much
  • Does AI Mark The End Of The ERP Era?
  • Guru: Deterministic Application Development With AI
  • What IBM’s Got Cooking In Db2 For i In The Summer TRs
  • IBM i PTF Guide, Volume 28, Number 25
  • The Power11 IBM i P05 Entry Machine Finally Arrives
  • Big Blue Finally Unveils First IBM i Tech Refreshes Of 2026
  • Guru: Analyzing User Session Statistics, Part 1
  • Relion Solutions Launches With A Focus On Customer Service
  • IBM i PTF Guide, Volume 28, Numbers 23 And 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