Note that there are some explanatory texts on larger screens.

plurals
  1. PONOT IN query... odd results
    primarykey
    data
    text
    <p>I need a list of users in one database that are not listed as the <code>new_user_id</code> in another. There are 112,815 matching users in both databases; <code>user_id</code> is the key in all queries tables.</p> <p><br /> Query #1 works, and gives me 111,327 users who are NOT referenced as a new_user_Id. But it requires querying the same data twice.</p> <pre><code>-- 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); </code></pre> <p><br /> Query #2 would be perfect... and I'm actually surprised that it's syntactically accepted. But it gives me a result that makes no sense.</p> <pre><code>-- 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); </code></pre> <p><br /> What exactly is the where clause in the second query doing, and why is it excluding 109,822 records from the results?</p> <p><br /> <strong>Note</strong> The above query is a simplification of what I'm really after. There are other/better ways to do the above queries... they're just representative of the part of the query that's giving me problems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload