BachPhi
BachPhi

Reputation: 180

SQL Find unique items AND one of the column value is NULL

I have a table w/ the format like below:

ItemNo  ItemDesc
11111   Item01 Description
11111   Item01 Description2
11111   <NULL>   
22222   <NULL>    
33333   Item03 Description
33333   Item03 Description2
33333   <NULL>

I'd like to find the unique item 22222. TIA.

Upvotes: 0

Views: 33

Answers (1)

MatBailie
MatBailie

Reputation: 86706

SELECT
    ItemNo
FROM
    yourTable
GROUP BY
    ItemNo
HAVING
        COUNT(*) = 1
    AND SUM(CASE WHEN ItemDesc IS NULL THEN 1 END) = 1

Upvotes: 2

Related Questions