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,

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 :)

commented: I didn't know about HAVING keyword in MySQL, thanks :) +4

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

hey thanx ppl....its working

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.