Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

query based on a many-to-many relationship

$
0
0
Hello. This is my first post here. I hope it makes since to all.

Let's suppose we have a table DOCUMENTS with the fields DocTitle (primary key), Format, Topic like so

DOCUMENTS
DocTitle Format Topic
---------------------------
A1 pdf Weather
A2 doc Sports
A3 doc News
A4 pdf Foreign

Then we have another table called USERS, that defines the people that created the documents.
Each document can have many users and each user can be in many documents. Primary key is UserCode

USERS
UserCode Name
----------------------
0001 John
0002 Steve
0003 Jack
0004 Bill

So, because of the many-to-many relationship we have another table, that defines which documents were created by which users. The key is both fields together.

DOCUMENTS_USERS
DocTitle UserCode
---------------------
A1 0001
A1 0002
A1 0003
A2 0001
A2 0002
A3 0001
A3 0003

These tables have the relationships
DOCUMENTS.DocTitle -> DOCUMENTS_USERS.DocTitle (1-many)
USERS.UserCode -> DOCUMENTS_USERS.UserCode (1-many)


What I could like is a query that displays the following:

DocTitle: A1
Format : pdf
Topic : Weather
Users : John
Steve
Jack

DocTitle: A2
Format : pdf
Topic : Weather
Users : John
Steve

etc

It may sound simple but I can't find the way. Please help, thank you.

Viewing all articles
Browse latest Browse all 13329

Trending Articles