title: Two different databases in MySQL
body: <p>I need to select all records on <code>database1</code> where <code>database1.table1.foreign_key</code> does not exist in <code>database2.table2.some_id</code>.</p>
  
  <p>The other questions here talk about joining both databases through their table's foreign keys but that doesn't work on my case since I'm looking for records where their foreign keys do not exist on the other database's table.</p>
  
  <p>Here's some sample data:</p>
  
  <p>On <code>database1</code>.<code>table1</code>:</p>
  
  <pre><code>id - name - foreign_key
  -----------------------
  
  1 - No need - 253
  
  2 - Don't need - 627
  
  3 - Need this - 166
  </code></pre>
  
  <p>On <code>database2</code>.<code>table2</code>:</p>
  
  <pre><code>id - name - some_id
  -------------------
  
  1 - Sample - 627
  
  2 - Another - 253
  </code></pre>
  
  <p>So with those sample data, after running the query, I expect to get</p>
  
  <p><code>3 - Need this - 166</code>.</p>
  
  <p>Here is my current solution which doesn't work.</p>
  
  <pre><code>SELECT fish_system_sandbox.receivables.*
  FROM fish_system_sandbox.receivables
  WHERE fish_system_sandbox.receivables.catch_datum_id NOT IN (SELECT inventory_sandbox2.holdings.catch_id FROM inventory_sandbox2.holdings)
  </code></pre>
  
  <p>This returns an empty result, and does not produce errors.</p>