<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Why no worky?</title>
	<link>http://ask.metafilter.com/49136/Why-no-worky/</link>
	<description>Comments on Ask MetaFilter post Why no worky?</description>
	<pubDate>Sat, 21 Oct 2006 18:46:21 -0800</pubDate>
	<lastBuildDate>Sat, 21 Oct 2006 18:46:21 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Why no worky?</title>
		<link>http://ask.metafilter.com/49136/Why-no-worky</link>	
		<description>SQLServerFilter: Quick question about views and using &quot;NOT IN&quot;. &lt;br /&gt;&lt;br /&gt; Okay, this should be easy, but for some reason my query isn&apos;t returning the desired results.  I have a view, vwPO, with one field called poNumber.  I have a table called purchaseOrders with many fields, one of which is also called poNumber.  &lt;br&gt;
&lt;br&gt;
vwPO is not generated from the purchaseOrders table.  vwPO has 19,925 distinct records, purchaseOrders has 20,382 distinct records.&lt;br&gt;
&lt;br&gt;
I need to return all poNumbers in vwPO that are not in the purchaseOrders table.&lt;br&gt;
&lt;br&gt;
If I run the following query, I get nothing, an empty recordset:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
SELECT ponumber FROM vwPO WHERE poNumber NOT IN (SELECT ponumber FROM purchaseorders)&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
If I use IN instead of NOT IN, the query returns 19661 records.  Why is my first query not returning the 264 poNumbers?  &lt;br&gt;
&lt;br&gt;
I know for a fact that there are poNumbers in the view that are not in the table, I just don&apos;t understand why they aren&apos;t being returned.  &lt;br&gt;
&lt;br&gt;
Admittedly my brain is fried right now and I feel like I&apos;m missing something easy....but at the moment, I don&apos;t get it.&lt;br&gt;
&lt;br&gt;
Help, please!  Thanks!</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2006:site.49136</guid>
		<pubDate>Sat, 21 Oct 2006 17:42:20 -0800</pubDate>
		<dc:creator>SoulOnIce</dc:creator>
		
			<category>sql</category>
		
			<category>server</category>
		
			<category>views</category>
		
			<category>notin</category>
		
			<category>database</category>
		
	</item> <item>
		<title>By: Doofus Magoo</title>
		<link>http://ask.metafilter.com/49136/Why-no-worky#746733</link>	
		<description>Maybe try fully-qualifying the field names with the table names? E.g.:&lt;br&gt;
&lt;pre&gt;SELECT ponumber FROM vwPO WHERE &lt;u&gt;&lt;b&gt;vwPO.&lt;/b&gt;&lt;/u&gt;poNumber NOT IN (SELECT ponumber FROM purchaseorders)&lt;/pre&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.49136-746733</guid>
		<pubDate>Sat, 21 Oct 2006 18:46:21 -0800</pubDate>
		<dc:creator>Doofus Magoo</dc:creator>
	</item><item>
		<title>By: blue mustard</title>
		<link>http://ask.metafilter.com/49136/Why-no-worky#746794</link>	
		<description>My guess is you have a NULL  ponumber in purchaseOrders. &lt;br&gt;
&lt;br&gt;
Try this:&lt;br&gt;
&lt;br&gt;
&lt;code&gt;SELECT ponumber FROM vwPO WHERE poNumber NOT IN &lt;br&gt;
(SELECT ponumber FROM purchaseorders WHERE ponumber IS NOT NULL)&lt;/code&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.49136-746794</guid>
		<pubDate>Sat, 21 Oct 2006 20:45:04 -0800</pubDate>
		<dc:creator>blue mustard</dc:creator>
	</item><item>
		<title>By: smackfu</title>
		<link>http://ask.metafilter.com/49136/Why-no-worky#746806</link>	
		<description>I can&apos;t answer your question, but I would do it like this:&lt;br&gt;
&lt;br&gt;
SELECT ponumber FROM vwPO&lt;br&gt;
LEFT OUTER JOIN purchaseorders&lt;br&gt;
ON vwPO.poNumber = purchasorders.ponumber&lt;br&gt;
WHERE purchaseorders.ponumber IS NULL</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.49136-746806</guid>
		<pubDate>Sat, 21 Oct 2006 20:59:52 -0800</pubDate>
		<dc:creator>smackfu</dc:creator>
	</item><item>
		<title>By: jimfl</title>
		<link>http://ask.metafilter.com/49136/Why-no-worky#747029</link>	
		<description>Don&apos;t you have it backwards? From your description, the extra records are in the purchaseorders table, not the view, so you want&lt;br&gt;
&lt;pre&gt;&lt;br&gt;
select ponumber &lt;br&gt;
  from purchaseorders &lt;br&gt;
 where ponumber &lt;br&gt;
 not in (select ponumber from vwPO)&lt;br&gt;
&lt;/pre&gt;&lt;br&gt;
Or have I missed something?&lt;br&gt;
&lt;br&gt;
Also, if the view is based on the table, why are there records missing? What does the view query look like? There may be a criterion that excludes some records from the view.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2006:site.49136-747029</guid>
		<pubDate>Sun, 22 Oct 2006 09:12:14 -0800</pubDate>
		<dc:creator>jimfl</dc:creator>
	</item>
	</channel>
</rss>
