Get all group by values in column a where all values in another column is true

Tags: ,



I have a table that looks like this:

enter image description here

I wanted to create a query that gives me a group by OrderID and Canbefulfilled but if there is a single 0 in Canbefulfilled column , I want that column to be 0

I the above case I am expecting, since OrderID 30 has one 0

OrderID  CanbeFulfilled
27             0
28             0
30             0 

Query wise

Select OrderID, Return0IfThereIfAny0(CanBeFulFilled)
FROM Table1
GROUP BY OrderID

I cannot figure out how I can do the Return0IfThereIsAny0 part.

Answer

I think min() does what you want:

SELECT OrderID, MIN(CanBeFulFilled)
FROM Table1
GROUP BY OrderID


Source: stackoverflow