[thelist] SQL: Need help for query within a store

Joshua Olson joshua at waetech.com
Thu Dec 5 21:31:01 CST 2002


I have a set of items in a store that have may have different costs and
shipping rates depending on the country and/or state that the item is sent
to.  For example, I have different shipping rates on all products if the
product is shipped to the continental US, Canada, Hawaii/Alaska.  I created
3 tables to handle this:

table "item" -- holds basic information about the item (name, description,
cost, etc)
table "shipping zone" -- an enumeration of all possible zones (it currently
has three records: US, Canada, and Hawaii/Alaska)
table "item_shipping_zone_assoc" -- a many-to-many relationship table that
has a compound PK on item_id and zone_id and only has one other field...
cost.  This table means "Shipping [this] item to [this] zone costs [this]
much"

Currently, I use two inner joins to grab the data from the database and then
use scripting side grouping logic to create the display which basically
looks like this:

product name        price              shipping rate 1
                                                      shipping rate 2

product name        price              shipping rate 1
                                                      shipping rate 2

etc.

But, now I must add in the idea that each product may have a different base
cost depending on the country the item is to be shipped to (not shipping
code, but actual item cost)  Now the display will need to look something
like this:

product name        price 1             shipping rate 1
                                price 2             shipping rate 2

product name        price  1           shipping rate 1
                                price 2           shipping rate 2

Is this reasonably possible to do with 1 query and 1 set of output logic?
It doesn't seem trivial to me.  TIA.

-joshua




More information about the thelist mailing list