What you'll get in a single, composite query, is repetitive field values for the single end of the one-to-many relationship. So if Foo:Bar :: 1:lots then as query that gets all the Bars and their Foos returns something like:
foo1 bar1
foo1 bar2
foo1 bar3
foo2 bar4
foo2 bar17
foo3 bar78
If you add in another table Baz that is Bar:Baz :: 1:lots, then you get something like this:
foo1 bar1 baz1
foo1 bar1 baz2
foo1 bar1 baz3
foo1 bar2 baz15
foo1 bar3 baz32
foo1 bar3 baz33
foo2 bar4 baz17
foo2 bar17 baz21
foo3 bar78 baz7
This is exactly what SQL is supposed to do. But it presents a bit of a problem when you're trying to output the answer in a pretty format. That's where your application code comes in. Set a $holder equal to the foo field and check to see if the new foo is different from the old one on each pass through your loop. Do the same with $bar. So:
$fooholder=NULL;
$barholder=NULL;
foreach ($result as $row_array) {
if(empty($fooholder)) {
$fooholder=$row_array['foo'];
$barholder=$row_array['bar'];
}
if ($fooholder!=$row_array['foo']){ //new foo value, so next section
//output $row_array['foo'] since it's new
$fooholder=$row_array['foo'];
}
if ($barholder!=$row_array['bar']){ //new bar value, so next section
//output $row_array['bar'] since it's new
$barholder=$row_array['bar'];
}
//output $row_array['baz']
}