Skip to content
Advertisement

How to not return result if one value is null?

There is a top level weight for a shipment but within that there is several weights for handling units. If one of these handling units has no value then I want the shipment to not show up in my query.

Here is my query –

This returns 123 as there is currently two boxs, one with a manual weight of 123 and one with 0.

It should not return this shipment at all as one of the manual weights is 0.

Advertisement

Answer

I would not use LEFT JOIN for this. I would simply use a HAVING clause. Assuming the weights are never negative:

If the weight could be 0 and you have negative values, then:

Note that SELECT DISTINCT is almost never used with GROUP BY. In this query, it is not needed.

EDIT:

If you want to filter out any shipment that has a NULL weight:

This requires that all be non-NULL.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement