<?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: Will these two queries yield same result? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639148#M190077</link>
    <description>&lt;P&gt;The two queries will yield the same results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although one is a left join and the other is an inner join, any additional rows of ID values in table A, but not in C or B, will not be included in the left join because of the WHERE clause applied to the left join, which will only allow rows with data from B and C.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, with the data you have presented there are no ID values in table A which are not in the other two tables, so using a left join will not make any difference here in any case.&lt;/P&gt;</description>
    <pubDate>Sat, 11 Apr 2020 14:34:56 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-04-11T14:34:56Z</dc:date>
    <item>
      <title>Will these two queries yield same result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639057#M190042</link>
      <description>&lt;P&gt;Will query A and query B yield same result below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Will these two queries yield same results even if the data changes? Is the left outer join along with where condition in Query A is equivalent to the inner join in Query B for all cases of data. Are there any cases for which the two queries will not be identical? Can Query A be replaced with Query B to get same results? &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Please advise.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Query A&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select a.key, a.val1, b.val2, c.val3&lt;BR /&gt;from a left join b&lt;BR /&gt;On a.key=b.key &lt;BR /&gt;left join c&lt;BR /&gt;on a.key=c.key&lt;BR /&gt;where b.val2=20 and c.val3=30&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Query B&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select a.key, a.val1, b.val2, c.val3&lt;BR /&gt;from a inner join b on a.key=b.key and b.val2=20&lt;BR /&gt;inner join c on a.key=c.key and c.val3=30&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Data:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Sample data below, you may change cases to break the query if you need to.&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;length key $1. val1 8.;&lt;BR /&gt;input key val1;&lt;BR /&gt;datalines;&lt;BR /&gt;a 0&lt;BR /&gt;a 10&lt;BR /&gt;b 10&lt;BR /&gt;b 20&lt;BR /&gt;c 30&lt;BR /&gt;d 40&lt;BR /&gt;e 50&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data b;&lt;BR /&gt;length key $1. val2 8.;&lt;BR /&gt;input key val2;&lt;BR /&gt;datalines;&lt;BR /&gt;b 20&lt;BR /&gt;b 10&lt;BR /&gt;c 10&lt;BR /&gt;d 20&lt;BR /&gt;e 20&lt;BR /&gt;f 20&lt;BR /&gt;g 10&lt;BR /&gt;g 20&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data c;&lt;BR /&gt;length key $1. val3 8.;&lt;BR /&gt;input key val3;&lt;BR /&gt;datalines;&lt;BR /&gt;a 10&lt;BR /&gt;b 20&lt;BR /&gt;b 30&lt;BR /&gt;c 20&lt;BR /&gt;c 30&lt;BR /&gt;c 40&lt;BR /&gt;d 30&lt;BR /&gt;e 50&lt;BR /&gt;h 20&lt;BR /&gt;h 30&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2020 22:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639057#M190042</guid>
      <dc:creator>vkumbhakarna</dc:creator>
      <dc:date>2020-04-10T22:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Will these two queries yield same result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639061#M190045</link>
      <description>&lt;P&gt;What happens if your run the two different codes on the data?&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Fri, 10 Apr 2020 21:36:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639061#M190045</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-10T21:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: Will these two queries yield same result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639135#M190072</link>
      <description>&lt;P&gt;See Maxim 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In short, &lt;U&gt;try it&lt;/U&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Apr 2020 11:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639135#M190072</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-11T11:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Will these two queries yield same result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639148#M190077</link>
      <description>&lt;P&gt;The two queries will yield the same results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although one is a left join and the other is an inner join, any additional rows of ID values in table A, but not in C or B, will not be included in the left join because of the WHERE clause applied to the left join, which will only allow rows with data from B and C.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, with the data you have presented there are no ID values in table A which are not in the other two tables, so using a left join will not make any difference here in any case.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Apr 2020 14:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639148#M190077</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-04-11T14:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Will these two queries yield same result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639238#M190109</link>
      <description>&lt;P&gt;The WHERE clause makes it compulsory that you have data coming from tables B and C, thereby transforming the left joins into inner joins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 00:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639238#M190109</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-12T00:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Will these two queries yield same result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639343#M190189</link>
      <description>&lt;P&gt;Thank you! I updated the data to test this.&amp;nbsp; I tested the scenario by adding 'f' to A and B and not in C. The where condition transforms the left join to inner join. Although, the left join with where condition would be a costlier (in terms of processing) as compared to the inner join because more&amp;nbsp; rows will be pulled in and later eliminated by where condition. So the inner join will be more efficient, i guess (in this particular scenario).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Query A*/&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select a.key, a.val1, b.val2, c.val3&lt;BR /&gt;from a left join b&lt;BR /&gt;On a.key=b.key&lt;BR /&gt;left join c&lt;BR /&gt;on a.key=c.key&lt;BR /&gt;where b.val2=20 and c.val3=30&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Query B*/&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select a.key, a.val1, b.val2, c.val3&lt;BR /&gt;from a inner join b on a.key=b.key and b.val2=20&lt;BR /&gt;inner join c on a.key=c.key and c.val3=30&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Data*/&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data a;&lt;BR /&gt;length key $1. val1 8.;&lt;BR /&gt;input key val1;&lt;BR /&gt;datalines;&lt;BR /&gt;a 0&lt;BR /&gt;a 10&lt;BR /&gt;b 10&lt;BR /&gt;b 20&lt;BR /&gt;c 30&lt;BR /&gt;d 40&lt;BR /&gt;e 50&lt;BR /&gt;f 70&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data b;&lt;BR /&gt;length key $1. val2 8.;&lt;BR /&gt;input key val2;&lt;BR /&gt;datalines;&lt;BR /&gt;b 20&lt;BR /&gt;b 10&lt;BR /&gt;c 10&lt;BR /&gt;d 20&lt;BR /&gt;e 20&lt;BR /&gt;f 20&lt;BR /&gt;g 10&lt;BR /&gt;g 20&lt;BR /&gt;f 20&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data c;&lt;BR /&gt;length key $1. val3 8.;&lt;BR /&gt;input key val3;&lt;BR /&gt;datalines;&lt;BR /&gt;a 10&lt;BR /&gt;b 20&lt;BR /&gt;b 30&lt;BR /&gt;c 20&lt;BR /&gt;c 30&lt;BR /&gt;c 40&lt;BR /&gt;d 30&lt;BR /&gt;e 50&lt;BR /&gt;h 20&lt;BR /&gt;h 30&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 17:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639343#M190189</guid>
      <dc:creator>vkumbhakarna</dc:creator>
      <dc:date>2020-04-12T17:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Will these two queries yield same result?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639654#M190331</link>
      <description>&lt;P&gt;Yes, but&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11920"&gt;@vkumbhakarna&lt;/a&gt;&amp;nbsp;may be right that the inner join query could be more efficient. Depends on the quality of the SQL interpreter.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 07:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Will-these-two-queries-yield-same-result/m-p/639654#M190331</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-04-14T07:02:21Z</dc:date>
    </item>
  </channel>
</rss>

