[thelist] SQL to return one result for duplicate values

Paul Cowan thelist at lists.evolt.org
Mon Apr 29 20:02:01 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.