0

Hi,

I am attempting to write a query to return whether or not a particular items value entered is the lowest value and also unique.

For example, if an item as 6 values against it e.g.

user_id item_id value
1 101 3
2 101 3
2 101 4
3 101 1
3 101 1
4 101 5

... the lowest unique value in this is the item with the value 4 because items with values 3 and 1 are not unique and although 5 is also unique it is not the lowest!


i want to find out a query for this....

3
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by dhr
1

Hi,

I am attempting to write a query to return whether or not a particular items value entered is the lowest value and also unique.

For example, if an item as 6 values against it e.g.

user_id item_id value
1 101 3
2 101 3
2 101 4
3 101 1
3 101 1
4 101 5

... the lowest unique value in this is the item with the value 4 because items with values 3 and 1 are not unique and although 5 is also unique it is not the lowest!


i want to find out a query for this....

Hi that can be done in MySQL using the following query

SELECT value FROM table_name GROUP BY value HAVING count(value) =1 ORDER BY value ASC

Hope that helps :)

Votes + Comments
I didn't know about HAVING keyword in MySQL, thanks :)
0

Upsilon is very close with that query. I will extend to give you the minimum value:

SELECT min(value) as value FROM table_name HAVING count(value) = 1
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.