I have a table called ItemTransaction
with columns itemId, Qty, BatchNo
columns. I want to select the items which all are having qty >=0
and <= 100
, and itemid
and batchno
unique.
The problem now is a single item can be repeated in the different batchno
with different qty
.
select
ItemID, Quantity, BatchNo
from
ItemTransaction
where
Quantity >= 0 and Quantity <= 100
group by
ItemID, Quantity, BatchNo
When I'm running the above query its giving duplicate values. Don't know how to fetch distinct values from the above mentioned condition.
Sample data
|ItemID | Quantity | BatchNo |
+----------------------------+
|1095 | 3 | 1 |
|1095 | 0 | 1 |
|1098 | 10 | 2 |
|1099 | 0 | 3 |
|1099 | 20 | 3 |
|1099 | 80 | 3 |
Expected output :
|ItemID | Quantity | BatchNo |
+----------------------------+
|1095 | 3 | 1 |
|1098 | 10 | 2 |
|1099 | 80 | 3 |
here quantity may be any which is greater in the batch or lesser in the batch.
Add
Distinct
keyword