I have this problem, I am a newbie in SQL. I have 3 tables:
For every document, there are corresponding products, one to many. What I can't figure out is how can I display the products of each document. Thank you in advance!
I'm so sorry but I really don't know how to do it, all I know are the basics of SQL.
Best How To :
Based on the schema you are providing, I will assume that you find all the products of each document based on 1. which document_group the document is in 2. which product_type the document_group is associated with If that is the case, this is what your query would look like:
SELECT doc_id, prod_id
FROM tbl_document AS td
JOIN tbl_document_group AS tdg ON td.doc_id = tdg.doc_id
JOIN tbl_product AS tp ON tdg.prod_type = tp.prod_type
WHERE doc_id = 1;
However, the scheme you outlined above is a little unconventional.