开发者

Find Missing Records

开发者 https://www.devze.com 2022-12-26 19:24 出处:网络
My SQL is a bit bad. I got a query that when I run it I return for example 10 rows but there are 15 in my where clause, how do I identify those 5 that I can\'t find?

My SQL is a bit bad. I got a query that when I run it I return for example 10 rows but there are 15 in my where clause, how do I identify those 5 that I can't find?

Off course I can dump it in MS Excel but how do I use SQL?

Its a simple query:

select * from customers w开发者_开发知识库here username in ("21051", "21052"...

Nothing else in the where clause, it return 10 rows but there are 15 usernames in there where clause.


To identify the missing rows:

SELECT * 
FROM (SELECT '21051' username 
      UNION ALL SELECT '21052'
      UNION ALL SELECT '21053'
      UNION ALL SELECT '21054') u 
WHERE u.username NOT IN (SELECT c.username FROM customers c) 
0

精彩评论

暂无评论...
验证码 换一张
取 消