开发者

Selecting a single row for each distinct combination in Oracle

Please consider this table:

firstName |  lastName | hobby
-----------------------------
Mike      |  Stone    | music
Sarah     |  James    | cooking
Mike      |  Stone    | jogging
Greg      |  Jones    | reading
Sarah     |  James    | music
Mike      |  Stone    | painting
-----------------------------

How do I select a single hobby (doesn't matter which), for each distinct firstName, lastName combination? (In Oracle)

An example of the desired result is:

firstName |  lastName | hobby
-----------------------------
Mike      |  Stone    | music
Sarah     |  James    | cooking
Greg      |  Jones    | reading
-----------------------------

Thank yo开发者_如何学JAVAu for any assistance..

Sam


You could do something like

select firstname, lastname, max(hobby) as hobby
   from names
   group by firstname, lastname

You could use other functions for max to give you different answers, for example, min.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜