<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Question on a practice of SQL1:essential, p161 of course note pdf in Advanced Programming</title>
    <link>https://communities.sas.com/t5/Advanced-Programming/Question-on-a-practice-of-SQL1-essential-p161-of-course-note-pdf/m-p/975885#M371</link>
    <description>&lt;P&gt;Note it is much easier to do in normal SAS instead of SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge sq.merchant sq.transaction(in=in2);
  by merchantid;
  if not in2;
  keep merchantname merchantid type zip;
  label merchantname ='Merchant Name'
        merchantid='Merchant ID'
        type='Merchant Type'
        zip='Merchant Zipcode'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 29 Sep 2025 01:57:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-09-29T01:57:12Z</dc:date>
    <item>
      <title>Question on a practice of SQL1:essential, p161 of course note pdf</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Question-on-a-practice-of-SQL1-essential-p161-of-course-note-pdf/m-p/975876#M369</link>
      <description>&lt;P&gt;This actually is not a question, but I was a little bit confused and frustrated by the very different thinking and coding habits people have. The practice question is as follows:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled1.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110187i6D89CA45276D49B3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled1.png" alt="Untitled1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The question asks to combine two table using &lt;EM&gt;left join&lt;/EM&gt;, and there are some entries&amp;nbsp;exist in one table but not in the other, and these (i.e., merchants with no transactions) are what should be in the result table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried twice using &lt;EM&gt;left join&lt;/EM&gt; and did not come up with the correct answer. Then I tried &lt;EM&gt;except&lt;/EM&gt; and still got no correct answer. And then I tried &lt;EM&gt;where var not in (subquery)&lt;/EM&gt; and it works and got the same result as the above screen capture. My code is as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct merchantname 
         label='Merchant Name',
       merchantid
         label='Merchant ID',
       type
         label='Merchant Type',
       zip
         label='Merchant Zipcode'
   from sq.merchant
   where zip=10001 and 
         merchantid not in
            (select merchantid
               from sq.transaction)
    order by 2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then I was thinking how does the answer using &lt;EM&gt;left join&lt;/EM&gt; to create this result. The code in the answer is as follows, and it creates the correct result (as shown in last screen capture):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_1-1759061059285.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110188i55D0AD0DBF1BB972/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dxiao2017_1-1759061059285.png" alt="dxiao2017_1-1759061059285.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What makes me a little bit confuse and frustrated is: using &lt;EM&gt;left join&lt;/EM&gt; in this situation. If the question did not ask to use &lt;EM&gt;left join&lt;/EM&gt;, I would probably choose &lt;EM&gt;where var not in (subquery)&lt;/EM&gt; first, because thinking this way is much easier for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I have two questions on using &lt;EM&gt;left join&lt;/EM&gt; in the above code: (1) the query does not select any column from one of the table (i.e., table b, &lt;EM&gt;sq.transaction&lt;/EM&gt;), I guess this is not the common practice of using &lt;EM&gt;left/right/inner join&lt;/EM&gt;? Are we suppose to select columns from all tables when using &lt;EM&gt;left/right/inner join&lt;/EM&gt;? (2) &lt;EM&gt;&lt;STRONG&gt;where&amp;nbsp;b.merchantid is null&lt;/STRONG&gt;;&lt;/EM&gt;, this part is bit difficult to understand, also I do not know how this part work, because table b (i.e., the &lt;EM&gt;sq.transaction&lt;/EM&gt; table) contains and only contains &lt;EM&gt;merchantid&lt;/EM&gt; that HAS transactions, also for the &lt;EM&gt;merchantid&lt;/EM&gt; column, there is no missing(or null) value, so how does SAS process &lt;STRONG&gt;&lt;EM&gt;where b.merchantid is null;&lt;/EM&gt;&lt;/STRONG&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone did this question can offer some ideas? Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Sun, 28 Sep 2025 12:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Question-on-a-practice-of-SQL1-essential-p161-of-course-note-pdf/m-p/975876#M369</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-09-28T12:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Question on a practice of SQL1:essential, p161 of course note pdf</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Question-on-a-practice-of-SQL1-essential-p161-of-course-note-pdf/m-p/975884#M370</link>
      <description>&lt;P&gt;When you do a LEFT join it means that all observations from the LEFT table will make it into the intermediate results.&amp;nbsp; And when there is an observation that did not match any observation from the RIGHT table then all of the variables contributed by the RIGHT table will have a missing value.&amp;nbsp; That is why the WHERE condition works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I find your answer much easier to follow.&amp;nbsp; But if you need multiple variables to perform the join then you cannot use the IN operator.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Sep 2025 01:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Question-on-a-practice-of-SQL1-essential-p161-of-course-note-pdf/m-p/975884#M370</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-09-29T01:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Question on a practice of SQL1:essential, p161 of course note pdf</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Question-on-a-practice-of-SQL1-essential-p161-of-course-note-pdf/m-p/975885#M371</link>
      <description>&lt;P&gt;Note it is much easier to do in normal SAS instead of SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge sq.merchant sq.transaction(in=in2);
  by merchantid;
  if not in2;
  keep merchantname merchantid type zip;
  label merchantname ='Merchant Name'
        merchantid='Merchant ID'
        type='Merchant Type'
        zip='Merchant Zipcode'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Sep 2025 01:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Question-on-a-practice-of-SQL1-essential-p161-of-course-note-pdf/m-p/975885#M371</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-09-29T01:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Question on a practice of SQL1:essential, p161 of course note pdf</title>
      <link>https://communities.sas.com/t5/Advanced-Programming/Question-on-a-practice-of-SQL1-essential-p161-of-course-note-pdf/m-p/975905#M372</link>
      <description>Thanks a lot, Tom! So the where condition works on the intermediate results.</description>
      <pubDate>Mon, 29 Sep 2025 07:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Advanced-Programming/Question-on-a-practice-of-SQL1-essential-p161-of-course-note-pdf/m-p/975905#M372</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-09-29T07:14:29Z</dc:date>
    </item>
  </channel>
</rss>

