aberns
asked on
MySQL query with multiple joins on 7 tables
Hello,
I need help with a query involving 7 tables. I've attached a visual schema that I hope will help.
What I want to do is select all of the documents and display their associated data in each table.
1. Show all the fields in all the records in docs
2. Match docs.doc_cat->category.cat _id to show the cat_name field in category
3. Match docs.doc_origin->origin.or igin_id to show the origin field in origin
4. Match docs.doc_id=mapchapters.do c_id AND chapters.chapter_id=mapcha pters.chap id to show the chapter field in the chapters table
5. Match docs.doc_id=mapcriteria.do c_id AND criteria.criteria_id=map_c riteria.cr iteria_id to show the criteria field in the criteria table
I was doing fine joning the origin, docs, and category tables,
but when it came to steps 4 and 5 I hit a wall.
each document has 1 category and 1 origin but many criteria and many chapters
document->chapters=many:ma ny
document->criteria=many:ma ny
I hope that I have provided all of the information needed to answer this query, but if not please let me know and I will get back to you right away.
Thanks,
Audg
I need help with a query involving 7 tables. I've attached a visual schema that I hope will help.
What I want to do is select all of the documents and display their associated data in each table.
1. Show all the fields in all the records in docs
2. Match docs.doc_cat->category.cat
3. Match docs.doc_origin->origin.or
4. Match docs.doc_id=mapchapters.do
5. Match docs.doc_id=mapcriteria.do
I was doing fine joning the origin, docs, and category tables,
but when it came to steps 4 and 5 I hit a wall.
each document has 1 category and 1 origin but many criteria and many chapters
document->chapters=many:ma
document->criteria=many:ma
I hope that I have provided all of the information needed to answer this query, but if not please let me know and I will get back to you right away.
Thanks,
Audg
SELECT * FROM docs AS d1,
LEFT JOIN category AS c1 ON d1.doc_cat=c1.cat_id
LEFT JOIN origin AS o1 ON d1.doc_origin=o1.origin_id
archiveschema.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, I'm pretty sure AS is optional. I know it is in MS SQL Server ...
ASKER
Join mapchapters mc
but
Join origin AS 01