Easiest way to eliminate NULLs in SELECT DISTINCT?

前端 未结 8 546
我寻月下人不归
我寻月下人不归 2020-12-10 01:28

I am working on a query that is fairly similar the following:

CREATE TABLE #test (a char(1), b char(1))

INSERT INTO #test(a,b) VALUES 
(\'A\',NULL),
(\'A\',         


        
8条回答
  •  感情败类
    2020-12-10 01:43

    Well, I don't particularly like this solution, but it seems the most appropriate to me. Note that your description of what you want sounds exactly like what you get with a LEFT JOIN, so:

    SELECT DISTINCT a.a, b.b
    FROM #test a
        LEFT JOIN #test b ON a.a = b.a
            AND b.b IS NOT NULL
    

提交回复
热议问题