Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> SQL on a poorly designed table

SQL on a poorly designed table

From: Pete Shankey <shankeyp_at_netscape.net>
Date: Thu, 28 Mar 2002 08:52:49 -0500
Message-ID: <3CA32031.1060206@netscape.net>


I am have a tough time figuring out how to make an SQL. The real table is a bit more complex, but here goes:

create table t3
(

   DOCUMENTID         number(12),
   chargeid           number(12),
   DOCUMENTTYPE       VARCHAR2(35),
   constraint t3_pk primary key (documentid)
     using index tablespace indx

  )

is loaded with data like:

create sequence t3_documentiID minvalue 1
/

insert into t3(documentid,chargeid,documenttype)

   values(t3_documentiID.nextval,1,'a')
/

insert into t3(documentid,chargeid,documenttype)

   values(t3_documentiID.nextval,1,'b')
/

insert into t3(documentid,chargeid,documenttype)

   values(t3_documentiID.nextval,1,'c')
/

insert into t3(documentid,chargeid,documenttype)

   values(t3_documentiID.nextval,1,'d')
/

insert into t3(documentid,chargeid,documenttype)

   values(t3_documentiID.nextval,2,'b')
/

insert into t3(documentid,chargeid,documenttype)

   values(t3_documentiID.nextval,3,'b')
/

insert into t3(documentid,chargeid,documenttype)

   values(t3_documentiID.nextval,3,'c')
/

insert into t3(documentid,chargeid,documenttype)

   values(t3_documentiID.nextval,4,'a')
/

insert into t3(documentid,chargeid,documenttype)

   values(t3_documentiID.nextval,4,'c')
/

The goal and my question is:
If have documenttype of 'b' then list and only list that row. If no documenttype 'b' then list any other row. Assuming this can be done I would take the SQL turn it into a view then inner join it with another table using chargeid as the join element. I think the main problem is the desginer of the schema did not propertly normalize the tables. However, this is what I have to work with.

Thank you, for your time.
Pete Received on Thu Mar 28 2002 - 07:52:49 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US