Do you know how can i get values from Field 1 that does not contain 0 value in Field 2.
For example I would like to select only "BBB" and "DDD" from the table below :
Field 1 | Field 2 |
---|---|
AAA | 1 |
AAA | 2 |
AAA | 0 |
BBB | 1 |
BBB | 2 |
CCC | 0 |
CCC | 2 |
DDD | 3 |
(BBB and DDD don’t contain 0 values in Field2)
4
Answers
Great! Thank you all for your immediate responses!
This can be done using
group by
andhaving
clauses, the condition is that the count of rows where Field2 equals 0 must be zero :Demo here
I can think of two ways in which it could be achieved:
Using Subquery:
Using
group by
andhaving
sample run
I would prefer
NOT EXISTS
Or with having clause
See example