开发者

Find Missing Records

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜