T-SQL: How to Select Values in Value List that are NOT IN the Table?

前端 未结 6 1875
天命终不由人
天命终不由人 2020-12-07 20:01

I have a list of e-mail addresses, some of them are in my table, some of them are not. I want to select all e-mails from that list and whether they are in the table or not.

6条回答
  •  时光说笑
    2020-12-07 20:32

    This Should work with all SQL versions.

    SELECT  E.AccessCode ,
            CASE WHEN C.AccessCode IS NOT NULL THEN 'Exist'
                 ELSE 'Not Exist'
            END AS [Status]
    FROM    ( SELECT    '60552' AS AccessCode
              UNION ALL
              SELECT    '80630'
              UNION ALL
              SELECT    '1611'
              UNION ALL
              SELECT    '0000'
            ) AS E
            LEFT OUTER JOIN dbo.Credentials C ON E.AccessCode = c.AccessCode
    

提交回复
热议问题