首页 > 解决方案 > how to query the result of UNION query

问题描述

Thank you for your time and apologies if question is silly. I have a result of union query that looks like below. As you can see A and C both have value2 other then NULL. How I can select B only? I would provide my sql tries but I run out of ideas. I tried count() and sum() and other methods but I always select A B C while I want to get only B. Thank you.

value1 value2 
  A    NULL 
  A    1
  B    NULL
  C    2
  C    3
  C    NULL

Thank you so much All for your help. I got the answer and much more! You all are awesome!

标签: sqlpostgresql

解决方案


这是你想要的吗?

select value1
from t
group by value1
having count(value2) = 0;

推荐阅读