[thelist] SQL to return one result for duplicate values

Paul Cowan paul at wishlist.com.au
Mon Apr 29 20:02:01 CDT 2002


Erik wrote:
> I would like to query this table and come up with the
> following result:
>
> word_id  word_value
> 1        butter
> 2        guns
> 5        gas

SELECT
	word_value, min(word_id) as first_word_id
FROM
	table_name
GROUP BY
	word_value

How's that? You don't have to use min(), you can use max(), or some DBMSes
have first(), or whatever.

Cheers,

Paul.



More information about the thelist mailing list