Print

Print


Andrew,

I realize this doesn't answer your question in the slightest, but why
not just do this in PHP after your SQL statement?

It's going to be a lot easier to wrote the PHP code for displaying
properly rather than fiddle with the awkward SQL statement that would
replicate it.

But then, I'm very lazy.
-Ross.

Andrew Darby wrote:

> Hello, all.  Based on the pretty SQL I saw in some recent posts, I
> thought I would fall on the mercy of the crowd, and see if anyone could
> help . . .
>
> I'm trying to display (using MySQL/PHP) a list of subject librarians and
> their associated subjects, in a neat table.  This gets me close:
>
> SELECT lname, fname, title, tel, email, supersubject FROM supersubs,
> staff WHERE supersubs.staff_id = staff.staff_id GROUP BY lname
>
> except only the first associated subject is delivered.
>
> The following query gets me all the data I need, but with all the
> librarian info duplicated:
>
> SELECT lname, fname, title, tel, email, supersubject FROM supersubs,
> staff WHERE supersubs.staff_id = staff.staff_id GROUP BY lname,
> supersubject
>
> Is there a way, in the SQL, to generate my "mama bear" set: i.e., with
> the subjects grouped together like so:
>
> Smith, Joe | English, History, Italian | 425-5000 | [log in to unmask]
> Turner, Ted | Math, Politics, Zoology | 425-5111 | [log in to unmask]
>
> Or do I have to run another query inside the php loop?  (I seem to
> remember, from a previous life, that you could do these "queries within
> queries" in ColdFusion.)
>
> Thanks, and I hope this doesn't qualify as a dumb question . . .
>
> Andrew Darby
>