Say I’ve got two tables:
Parent
id | name
Child
id | parentId | name
Each parent could have an infinite number of children. What are some common ways to put a parent’s children into the same result set as the parent? Is there a way to do this without creating a row for each child entry?
I’ve already realized that it’s easier (and probably much more efficient) to just do a second query for the child items, I’m just curious as to what some approaches are. One approach I found was to use GROUP_CONCAT: http://hussfelt.net/blog/sql/group-join-one-to-many-relationship.
Are there any other methods available to achieve the desired result? The question is tagged foxpro because it’s specific to my implementation, but an agnostic answer would be great too.
For processing, you can query in common regardless of back-end, such as
Then, you can scan through the result set and build out whatever else you need, such as a summary of all names per a single parent ID.