Re: confused by select.

From: "Brett W(dot) McCoy" <bmccoy(at)chapelperilous(dot)net>
To: John <john(at)akadine(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: confused by select.
Date: 2000-07-06 20:38:49
Message-ID: Pine.LNX.4.10.10007061623300.13683-100000@chapelperilous.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, 6 Jul 2000, John wrote:

> I would like to get the id's where the customer has purchased an item of a
> specific type.
>
> Problem A: most people order more than one item at a time.
> So the 'items' field is a colon delimitted text field containing the
> skus of the purchased items.
> <example of items field -- 1111:1212:W233:QA66>

I don't understand why you are doing it this way? Why not create a
history table with individual skus that are each part of an order?

create table history (id int2, order int2, sku char(4));

You would, of course, put some constraints to make sure that skus in the
history table actually exist in the inventory table (i.e., foreign key),
and have the history id as a serial type to make the primary key. Then you
can have the same order number reference multiple inventory items.

Then you can do easier joins, search for unique orders with a count of
items in each order, and so forth, all in SQL.

Brett W. McCoy
http://www.chapelperilous.net
---------------------------------------------------------------------------
Virtue does not always demand a heavy sacrifice -- only the willingness
to make it when necessary.
-- Frederick Dunn

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ebbe Poulsen 2000-07-06 20:59:07 Get: Month & Month-1 & Month+1
Previous Message John 2000-07-06 20:17:43 confused by select.