Re: Query returns duplicate rows
| From: | Justin Patrin | Date: | Wed, 21 Jul 2004 21:27:38 +0000 |
| Subject: | Re: Query returns duplicate rows | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35430@lists.php.net to get a copy of this message | ||
On Wed, 21 Jul 2004 17:09:35 -0400, Brock Jimmy D Contr 74 MDSS/SGSI
<jimmy.brock@wpafb.af.mil> wrote:
> These two tables do not have a relation, so there is nothing to join.
>
> Basically, what I'm trying to is this:
> Users need to score elements. The elements are assoicatied with standards.
> A standard may have 1 to 29 elements associated with it.
>
> For users to score the elements they need to see the criteria for that particular element.
>
> Thanks for the help though.
>
>
You may want to try selecting all selected elements, then all selected
scores, then loop through them individually. Doing a join without an
ON clause is IMHO not a good choice.
>
> -----Original Message-----
> From: Justin Patrin
> To: Brock Jimmy D Contr 74 MDSS/SGSI
> Cc: php-db@lists.php.net
> Sent: 7/21/2004 5:02 PM
> Subject: Re: [PHP-DB] Query returns duplicate rows
>
> On Wed, 21 Jul 2004 16:29:37 -0400, Brock Jimmy D Contr 74 MDSS/SGSI
> <jimmy.brock@wpafb.af.mil> wrote:
> > My query is returning duplicates rows.
> >
> > table: elements
> > elementId
> > standardId
> > elementtext
> > category
> > mcode
> > linenum
> >
> > table: scores
> > scoreId
> > taskId
> > scores
> >
> > Here's my query:
> > SELECT distinct elementtext,cateogy,mcode,linenum,scores,scoreId
> > FROM elements, scores
> > WHERE scores.taskId='12'
> > AND elements.standardId='APR.05'
> >
> > This is returning duplicate rows, even though I'm using the DISTINCT
> keyword.
> >
> > If I remove the field scoreId it is fine.
> >
> > Any suggestions?
> >
>
> Should you perhaps be doing some kind of ON clause to that join? It's
> joining every record in elements with every element in scores. You
> need to tell it what fields to join on.
>
> Also, doing a distinct on that many fields at once could be very
> expensive. Better tp refine your query or data model.
>
> --
> DB_DataObject_FormBuilder - The database at your fingertips
> http://pear.php.net/package/DB_DataObject_FormBuilder
>
> paperCrane --Justin Patrin--
>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--