Subject return max 1 row from one of tables in a join
Author Matt Clark
Hello all,
This may turn out to be a little cryptic so I'll start simple and work
up if anyone suggests something I can't actually do.

I have an amalgamation of several tables. Specifically a product table
with several detail tables that are linked by a stock code(sku). A
couple of the tables may or may not return 1 or more matching records by
stock code. Easy left join so far.
eg,
from item_history
left join locations on item_history.sku = locations.sku

problem is, if there is more than one matching row in locations, I still
only want exactly 1 row per sku in the top level.
The reason for this anomaly is that there /should/ only be one location
per sku but we aren't going to be enforcing this rule for some business
reason so I need to be prepared to handle this.

Summary, I need to guarantee one row per sku regardless of the number of
matching rows in a joined table.

Regards, Mattc


Maplin Electronics Ltd.
www.maplin.co.uk

This message is intended only for the use of the person(s) ("The intended
recipient(s)") to whom it is addressed. It may contain information which is
privileged and confidential within the meaning of applicable law. If you
are not the intended recipient please contact the sender as soon as possible.
The views expressed in this communication may not necessarily be the views
held by Maplin Electronics Ltd.