List:General Discussion« Previous MessageNext Message »
From:Petre Agenbag Date:December 9 2002 11:45am
Subject:distinct and distinctrow
View as plain text  
sql,query

Hi List

Please can someone help me with this:

I need to "filter" duplicate entries from my result query, but there's a
twist...

The table has something like this:

id	name	key
1	name1	key1
2	name2	key2
3	name3	key3
4	name1	key1
5	name 1	key1
6	name2	key2


Now I want to search the table for all unique name/key combinations.

I tried 
select DISTINCTROW name,key from table order by name;

but, it returns
name1	key1
name2	key2
name3	key3
name 1	key1

Where name 1 key1 was obviously a typo, yet, I would ideally want to
filter or flag this through some kind of logic => ( there is already a
key1 associated with a name1, cannot associate key1 with another name!)

Firstly, my problem is with the query as I quoted it itself, ie, is that
the best way to prevent duplicates? I might also try this:

select DISTINCTROW MAX(id),name,key from table group by name;
but this will only ensure that only the LATEST key/name "pair" is listed
right?

Second, how do I translate my "logic" above into SQL? Or should I do it
in PHP?

Thanks.



 





Thread
distinct and distinctrowPetre Agenbag9 Dec
  • Re: distinct and distinctrowMertens Bram10 Dec
  • Re: distinct and distinctrowBenjamin Pflugmann10 Dec
  • Re: distinct and distinctrowRafal Jank10 Dec