Re: repeating records

From: Date: Wed, 30 Aug 2000 17:07:10 +0000
Subject: Re: repeating records
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-2489@lists.php.net to get a copy of this message
On Wed, 30 Aug 2000, Adv. Systems Design wrote: > I have 3 tables: lesson, lesson_preq, and > preqs...basically each lesson has many prerequisites > (lesson_preq composed of lesson id and prereq id) and > the prerequisites are stored in preqs (prereq id and > prereq name). > > Now I want to list all the lessons and have the name > appear for each prerequisite...the query below gives > me what I want, but each lesson is repeated for each > prerequisite...I would like to list the lesson only > once and have all prerequisites appear (in name) for > that lesson...since we do not have subselects...this > is kind of confusing...any ideas? > > SELECT lesson.l_id, lesson.title, preqs.prereq > FROM lesson, lesson_preq, preqs > WHERE lesson_preq.preq_id=preqs.preq_id > AND lesson_preq.l_id=lesson.l_id > > Thanks I'm not sure what the format of the output you want is, but I would use a ORDER BY lesson.l_id so that my output was returned to me in lesson.l_id order. That would at least look nicer. The output from this would still look something like: l_id title prereq 1 l1 l1p1 1 l1 l1p2 1 l1 l1p3 2 l2 l2p1 3 l3 l3p1 3 l3 l3p2 I hope this is of at least some help. Or perhaps you might what to give an example of what you would like the output to look like. John

« previous php.db (#2489) next »