select one row based on multiple distinct row values

If i have 4 rows and want to select rows based on a single column’s distinct values, how do i do this?

Eg:
Name, value

john 1
john 2
michael 3
michael 5

result
john 1
michael 3

Query:

GROUP BY Name and use any aggregate function with the value MIN or MAX 

SELECT Name, MIN(value)FROM table GROUP BY Name

And to get below Result use MAX(value)
john 2
michael 5

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s