Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Query for Cross Reference Table

 
   Database Help (Home) -> Oracle RSS
Next:  Sales Commission  
Author Message
hotima

External


Since: Feb 16, 2009
Posts: 2



(Msg. 1) Posted: Mon Feb 16, 2009 7:25 am
Post subject: Query for Cross Reference Table
Archived from groups: comp>databases>oracle>misc (more info?)

Hi all,

I have a cross-reference table which stores student class enrollment
info:

Table Name: ENROLLMENT_XREF

XREFID STUDENT CLASS
------ ------- -----
1 MARY MATH
2 MARY SCIENCE
3 MARY COOKERY
4 JIM MATH
5 JIM AUTO-REPAIR
6 JIM ENGLISH
7 JOHN COOKERY
8 JOHN ENGLISH
9 JOHN SCIENCE

The original table uses studentID and classID instead of real name;
however I put the full name in here in order to make thing more easily
to understand....

If I want to know which students have enrolled in MATH, the query is
SELECT STUDENT FROM ENROLLMENT_XREF WHERE CLASS='MATH'

If I want to know which students have enrolled in MATH and COOKERY:
SELECT STUDENT FROM
ENROLLMENT_XREF table1,
(SELECT STUDENT FROM ENROLLMENT_XREF WHERE CLASS='MATH') view1
WHERE
view1.STUDENT=table1.STUDENT AND
table1.CLASS='COOKERY';

But what is the query for knowing which students has enrolled in MATH,
COOKERY and SCIENCE ?

Yes I can further add extra in-line view based on the last query;
however my requirement is to build this query dynamically. Also the
number of classes can be included and excluded, like:
Find out which students have enrolled in MATH but not SCIENCE.

Do I need to create another table to do back-referencing ? Or I simply
go the wrong direction in building the query ?

Any input or pointer is absolutely welcome. TIA !!

 >> Stay informed about: Query for Cross Reference Table 
Back to top
Login to vote
Mark D Powell

External


Since: Dec 20, 2007
Posts: 294



(Msg. 2) Posted: Mon Feb 16, 2009 7:25 am
Post subject: Re: Query for Cross Reference Table [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Feb 16, 6:39 am, hotima wrote:
> Hi all,
>
> I have a cross-reference table which stores student class enrollment
> info:
>
> Table Name: ENROLLMENT_XREF
>
> XREFID  STUDENT   CLASS    
> ------  -------   -----
> 1       MARY      MATH
> 2       MARY      SCIENCE
> 3       MARY      COOKERY
> 4       JIM       MATH
> 5       JIM       AUTO-REPAIR
> 6       JIM       ENGLISH
> 7       JOHN      COOKERY
> 8       JOHN      ENGLISH
> 9       JOHN      SCIENCE
>
> The original table uses studentID and classID instead of real name;
> however I put the full name in here in order to make thing more easily
> to understand....
>
> If I want to know which students have enrolled in MATH, the query is
> SELECT STUDENT FROM ENROLLMENT_XREF WHERE CLASS='MATH'
>
> If I want to know which students have enrolled in MATH and COOKERY:
> SELECT STUDENT FROM
> ENROLLMENT_XREF table1,
> (SELECT STUDENT FROM ENROLLMENT_XREF WHERE CLASS='MATH') view1
> WHERE
> view1.STUDENT=table1.STUDENT AND
> table1.CLASS='COOKERY';
>
> But what is the query for knowing which students has enrolled in MATH,
> COOKERY and SCIENCE ?
>
> Yes I can further add extra in-line view based on the last query;
> however my requirement is to build this query dynamically.  Also the
> number of classes can be included and excluded, like:
> Find out which students have enrolled in MATH but not SCIENCE.
>
> Do I need to create another table to do back-referencing ? Or I simply
> go the wrong direction in building the query ?
>
> Any input or pointer is absolutely welcome. TIA !!

OP also posted to server. Responses exist there.

--

 >> Stay informed about: Query for Cross Reference Table 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
SQL to find the list of objects that reference a table - Hi all I want to find all the objects that reference a given table. Can anyone please provide the SQL query to do the same? Thanks Saravanan

a cross tab?? - hi all, i have a little problem with a formula in oracle which i dont know how to do it all, i have done many attempts but no success! i will write the result i am aiming to get here: Month Year SP-20.2 SP-20.1 SP-20.6 ----- ---- ..

Getting reference from a newly inserted object - HI I am troubling in getting reference of an user defined type after inserted it into a table. For example, I use a java program to insert an user defined object: .. .. .. OraclePreparedStatement pstmt = (OraclePreparedStatement)conn.prepareStatement..

Query Question -- Query Using Monthly Data - Hello everyone. I currently have a simple table, DAILY, containing various daily transactions. The table has a date column, transaction 1, transaction2, transaction3 etc. Example: DATE Transaction1 Transaction2 Transaction3 1-1-2007 ...

How to update a table with another table - Hi to All, I have in my 'schema' 2 tables: CREATE TABLE T_ITEMS ( ITEM_GROUP VARCHAR2(10 BYTE) NOT NULL, ITEM_CODE VARCHAR2(25 BYTE) NOT NULL, ITEM_DESCRIPTION VARCHAR2(40 BYTE) NOT NULL, ITEM_QTA NUMBER(16,4), ITEM_PRICE NUMBER(18,5) ) TABLESPACE..
   Database Help (Home) -> Oracle All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]