Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As <a href="https://stackoverflow.com/a/17095920/57611">Randy suggested</a>, you can just change <code>IN</code> to <code>NOT IN</code>. However, I would encourage you to start thinking in terms of JOINs and <code>EXISTS</code> (semi-joins):</p> <pre><code>SELECT A.* -- try to use explicit columns though instead of * FROM dbo.ActiveListing A WHERE Right(A.[seller-id], 4) &lt;&gt; '-XRU' --may improve performance AND NOT EXISTS ( -- this is actually an anti-semi-join SELECT * FROM dbo.Product P WHERE P.PurchaserID = 60741 AND Right(P.id, 4) = '-XRU' AND A.[seller-id] = P.id ) ; SELECT A.* -- try to use explicit columns though instead of * FROM dbo.ActiveListing A LEFT JOIN dbo.Product P ON P.PurchaserID = 60741 AND Right(P.id, 4) = '-XRU' AND A.[seller-id] = P.id WHERE Right(A.[seller-id], 4) &lt;&gt; '-XRU' --may improve performance AND P.id IS NULL ; </code></pre> <p>Note my addition that "may improve performance' also eliminates any <code>NULL</code> values, so adjust accordingly if <code>A.[seller-id]</code> can be <code>NULL</code>.</p> <p>If I have understood this backward and you want the rows from <code>Product</code> that aren't in <code>ActiveListing</code> we just flip the tables and conditions:</p> <pre><code>SELECT P.* -- try to use explicit columns though instead of * FROM dbo.Product P WHERE P.PurchaserID = 60741 AND Right(P.id, 4) = '-XRU' AND NOT EXISTS ( -- this is actually an anti-semi-join SELECT * FROM dbo.ActiveListing A WHERE P.id = A.[seller-id] ) ; SELECT P.* -- try to use explicit columns though instead of * FROM dbo.Product P LEFT JOIN dbo.ActiveListing A ON P.id = A.[seller-id] WHERE P.PurchaserID = 60741 AND Right(P.id, 4) = '-XRU' AND A.[seller-id] IS NULL ; </code></pre>
 

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