?
Solved

Many to many relationship Query

Posted on 2003-03-10
9
Medium Priority
?
356 Views
Last Modified: 2009-07-29
I want to know the query I need to write for such a situation:
Say student, course tables exist. To find a list of all student details and all the courses that a particular student undertakes.
eg:
studentid1
         courseid1 ......
         courseid2 ......
studentid2
         courseid3 ......
         courseid4 ......
   
0
Comment
Question by:cgibin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:Hummusx
ID: 8105327
Ok well presumably you have an XRef table to connect them somehow..then:

SELECT Student.ID, Course.ID FROM Student INNER JOIN (StudentCourseXRef INNER JOIN Course ON StudentCourseXRef.CourseID = Course.ID) ON Student.ID = StudentCourseXRef.StudentID

I think that should do it.

0
 
LVL 54

Expert Comment

by:nico5038
ID: 8105332
For this an additional table "StudentCourse" is needed.
Only the fields studentid and courseid are needed there and will have to be defined to be a unique key to prevent dupicate entries.

Nic;o)
0
 
LVL 2

Expert Comment

by:Hummusx
ID: 8105377
Right, that's pretty much the only way to do many-many relationships.  The StudentCourse table just provides a mapping between the Student and Course tables, where each record represents one course that one student is taking/took.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:h_mahadevan
ID: 8110310

You need another table studentcourse which maps the two table.

Otherwise create an alias which refers the student table itself while create a query
0
 

Author Comment

by:cgibin
ID: 8110907
how is it possible to to query by creating an alias? I'm not sure whether they will be a junction table so I want to know this alternative. Can you please show me an example query?
0
 

Author Comment

by:cgibin
ID: 8111324
how is it possible to to query by creating an alias? I'm not sure whether they will be a junction table so I want to know this alternative. Can you please show me an example query?
0
 

Author Comment

by:cgibin
ID: 8111928
how is it possible to to query by creating an alias? I'm not sure whether they will be a junction table so I want to know this alternative. Can you please show me an example query?
0
 

Expert Comment

by:h_mahadevan
ID: 8116829
My guess is that!

how do you find who is the manager of whom in emp table in oracle.
you create an alias for emp table.

Try. but i am not sure
0
 
LVL 2

Accepted Solution

by:
Hummusx earned 200 total points
ID: 8116842
You are going to need the junction table in order to do many-to-many relationships.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question