fhg
Volume 11, Number 4 -- January 26, 2011

Don't Let Users Wreck Their Joins

Published: January 26, 2011

by 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


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
E-mail: software@worksright.com
Web site: www.worksright.com


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

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


 
The Four Hundred
Power Systems Stabilize in Q4 Thanks to Entry Boxes

The Midrange, Stuck in the Middle with You

There's More IT Jobs, But Stingy Salaries Cause Unrest

As I See It: Fractal Expressionism

Public IBM i Software Companies Enjoyed Good Returns in 2010

Four Hundred Stuff
Data Domain Delivers Native IBM i Support

MySQL Support Options for IBM i Customers

Security Scoreboard Adds Analytics to Crowd-Sourced Product Reviews

ASCI Delivers Java Support with Job Scheduler

Capitalware Unveils New WebSphere MQ Auditing Tool

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

System i PTF Guide
September 25, 2010: Volume 12, Number 39

September 18, 2010: Volume 12, Number 38

September 11, 2010: Volume 12, Number 37

September 4, 2010: Volume 12, Number 36

August 28, 2010: Volume 12, Number 35

August 21, 2010: Volume 12, Number 34

TPM at The Register
Intel commits $10bn to buybacks, juices dividend

AMD CEO downed by lost server-chip business

Cisco-EMC Arcadia experiences integrator-friendly re-birth

Ex-eBay CEO lands post-purge HP board seat

Weak October gives F5 a Cisco moment

US Navy puts stops on server spending

IBM claims its big blue tools penetrate markets

Dell hooks server tools into VMware vCenter

Microsoft and HP Frontline marriage births appliance iron

IBM (nearly) hits $100bn in 2010 sales

Univa forks Oracle's Sun Grid Engine

Chip upstart Tilera lines up $45m in funding

THIS ISSUE SPONSORED BY:

ProData Computer Services
WorksRight Software
System i Developer


Printer Friendly Version


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?

Four Hundred Guru

BACK ISSUES




 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2011 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement