Say I have a table containing articles (article_id, article_name) and another table containing the names of people (person_id, person_name) that ordered the articles. Plus an intermediary table, say articles-people (article_id, person_id).
Is there an elegant way I could do a single SELECT to get all the articles and the associated purchasers such that the articles would each listed in headers and the people are listed under the respective articles they’ve bought?
Also, is there a SELECT that would fetch the needed information but avoid a result like this (which looks like a badly structured DB):
- article_id:1,article_name:penlight,purchaser_id:1, purchaser_name:fred
- article_id:1,article_name:penlight,purchaser_id:2, purchaser_name:albert
- article_id:1,article_name:penlight,purchaser_id:3, purchaser_name:sonia
- …
This should print out rows with values.
So that you can have both solutions in the same post, here is the solution you were talking about with JNK.