Here is a sample of the data I have:
-----------------------------------
ID | Item | Value
1 | Carrot | 0
2 | Carrot | 1
3 | Peas | 1
4 | Peas | 2
5 | Peas | 3
6 | Salad | 0
7 | Salad | 3
8 | Salad | 5
9 | Corn | 0
-----------------------------------
I want to do a query where the lines with values 0 appear if:
- They are the only value for that item
- There is more than one other value for that item
Or another way of saying is they should not be in the result if:
- There is one and only one other value for the same item
Note that the pair (item, value) is unique in my data.
So for the data sample, the result of the query should be like this (only the first line goes away):
-----------------------------------
ID | Item | Value
2 | Carrot | 1
3 | Peas | 1
4 | Peas | 2
5 | Peas | 3
6 | Salad | 0
7 | Salad | 3
8 | Salad | 5
9 | Corn | 0
-----------------------------------
What would be the best and most efficient way to do this?
You will have to group the data by Item, so one possibility is
See this SQLFiddle