Re: Query returns duplicate rows
| From: | David Robley | Date: | Thu, 22 Jul 2004 08:34:17 +0000 |
| Subject: | Re: Query returns duplicate rows | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-35434@lists.php.net to get a copy of this message | ||
On Thu, 22 Jul 2004 05:59, Brock Jimmy D Contr 74 Mdss/Sgsi 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?
I think you may misunderstand exactly what DISTINCT does. The keyword
applies to the entire record, not individal fields, and will effectively
delete any duplicate rows. ScoreId is presumably a unique ID for the
record; that being the case you can expect all selected rows will be
different.
Cheers
--
David Robley
Backups? We don' *NEED* no steenking backups.