I need a list of users in one database that are not listed as new_user_id in another. Both databases have 112,815 users; user_id is the key in all query tables.
Query No. 1 works and gives me 111,327 users that are not referenced as new_user_Id. But for this you need to query the same data twice.
-- 111,327 GSU users are NOT listed as a CSS new user -- 1,488 GSU users ARE listed as a new user in CSS -- select count(gup.user_id) from gsu.user_profile gup join (select cud.user_id, cud.new_user_id, cud.user_type_code from css.user_desc cud) cudsubq on gup.user_id = cudsubq.user_id where gup.user_id not in (select cud.new_user_id from css.user_desc cud where cud.new_user_id is not null);
Request number 2 would be perfect ... and I'm really surprised that it is syntactically accepted. But this gives me a result that does not make sense.
-- This gives me 1,505 users... I've checked, and they are not -- referenced as new_user_ids in CSS, but I don't know why the ones -- that were excluded were excluded. -- -- Where are the missing 109,822, and whatexcluded them? -- select count(gup.user_id) from gsu.user_profile gup join (select cud.user_id, cud.new_user_id, cud.user_type_code from css.user_desc cud) cudsubq on gup.user_id = cudsubq.user_id where gup.user_id not in (cudsubq.new_user_id);
What is the where clause in the second query, and why does it exclude 109,822 records from the results?
Note The above query simplifies what I'm really doing. There are other / better ways to fulfill the above requests ... they just form part of the request that gives me problems.
source share