<?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>question Re: Hive Query not working in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135298#M39617</link>
    <description>&lt;P&gt;It doesn't work because, to quote the related &lt;A href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+GroupBy#LanguageManualGroupBy-Selectstatementandgroupbyclause"&gt;wiki page&lt;/A&gt;: &lt;EM&gt;When using group by clause, the select statement can only include columns included in the group by clause, and aggregate functions on other columns. &lt;/EM&gt;So, your query will work if you remove "group by"  and "min".&lt;/P&gt;</description>
    <pubDate>Sun, 04 Sep 2016 11:50:47 GMT</pubDate>
    <dc:creator>pminovic</dc:creator>
    <dc:date>2016-09-04T11:50:47Z</dc:date>
    <item>
      <title>Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135291#M39610</link>
      <description>&lt;P&gt;&amp;gt; Not sure can use select min(from_date) clause &lt;/P&gt;&lt;P&gt;create table employees2_final stored as ORC tblproperties (‘orc.compress’=‘SNAPPY’)
AS 
SELECT 
e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, select min(s.from_date) from new2_salaries s 
GROUP BY s.emp_no 
WHERE s.emp_no = e.emp_no as hire_date_new from employees e. &lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2016 04:34:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135291#M39610</guid>
      <dc:creator>sanjeevanmahaja</dc:creator>
      <dc:date>2016-09-03T04:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135292#M39611</link>
      <description>&lt;P&gt;@sanjeevan mahajan&lt;/P&gt;&lt;P&gt;Can you try this out:&lt;/P&gt;&lt;PRE&gt;create table employees2_final stored as ORC tblproperties (‘orc.compress’=‘SNAPPY’) AS 
SELECT e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, min(s.from_date) from new2_salaries s, employees e
WHERE s.emp_no = e.emp_nosel
GROUP BY s.emp_no
&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Sep 2016 04:47:17 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135292#M39611</guid>
      <dc:creator>dkozlowski</dc:creator>
      <dc:date>2016-09-03T04:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135293#M39612</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3675/dkozlowski.html" nodeid="3675"&gt;@Daniel Kozlowski :  It's still gives an exception "Expression not in Group By key emp_no" &lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2016 04:53:32 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135293#M39612</guid>
      <dc:creator>sanjeevanmahaja</dc:creator>
      <dc:date>2016-09-03T04:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135294#M39613</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3675/dkozlowski.html" nodeid="3675"&gt;@Daniel Kozlowski&lt;/A&gt;  Please see attached screen grab &lt;A href="https://community.cloudera.com/legacyfs/online/attachments/7331-screen-shot-2016-09-02-at-225412.png"&gt;screen-shot-2016-09-02-at-225412.png&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2016 04:55:21 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135294#M39613</guid>
      <dc:creator>sanjeevanmahaja</dc:creator>
      <dc:date>2016-09-03T04:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135295#M39614</link>
      <description>&lt;P&gt;@sanjeevan mahajan&lt;/P&gt;&lt;P&gt;How about this:&lt;/P&gt;&lt;PRE&gt;create table employees2_final stored as ORC tblproperties (‘orc.compress’=‘SNAPPY’) AS SELECT e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, min(s.from_date) from new2_salaries s, employees e
WHERE s.emp_no = e.emp_nosel
GROUP BY s.emp_no, s.from_date
&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Sep 2016 04:58:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135295#M39614</guid>
      <dc:creator>dkozlowski</dc:creator>
      <dc:date>2016-09-03T04:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135296#M39615</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3675/dkozlowski.html" nodeid="3675"&gt;@Daniel Kozlowski Still not &lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2016 05:07:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135296#M39615</guid>
      <dc:creator>sanjeevanmahaja</dc:creator>
      <dc:date>2016-09-03T05:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135297#M39616</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/2408/sanjeevanmahajan05.html" nodeid="2408"&gt;@sanjeevan mahajan&lt;/A&gt; &lt;/P&gt;&lt;P&gt;I have made quite few attempts - the ones that actually should work. Similar to&lt;/P&gt;&lt;PRE&gt;SELECT j.* 
FROM new2_salaries j 
WHERE j.from_date = 
(SELECT MIN(j2.from_date) FROM new2_salaries j2 WHERE j.empl_no = j2.empl_no);
&lt;/PRE&gt;&lt;P&gt;Unfortunately, this is not working due to an existing bug: &lt;A href="https://issues.apache.org/jira/browse/HIVE-8960"&gt;https://issues.apache.org/jira/browse/HIVE-8960&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2016 06:10:14 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135297#M39616</guid>
      <dc:creator>dkozlowski</dc:creator>
      <dc:date>2016-09-03T06:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135298#M39617</link>
      <description>&lt;P&gt;It doesn't work because, to quote the related &lt;A href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+GroupBy#LanguageManualGroupBy-Selectstatementandgroupbyclause"&gt;wiki page&lt;/A&gt;: &lt;EM&gt;When using group by clause, the select statement can only include columns included in the group by clause, and aggregate functions on other columns. &lt;/EM&gt;So, your query will work if you remove "group by"  and "min".&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2016 11:50:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135298#M39617</guid>
      <dc:creator>pminovic</dc:creator>
      <dc:date>2016-09-04T11:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135299#M39618</link>
      <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/177/pminovic.html"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/2408/sanjeevanmahajan05.html"&gt;@sanjeevan mahajan&lt;/A&gt;&lt;/P&gt;&lt;P&gt;... and to add to what Predrag stated based on the documentation, the same is true for all other databases, including Oracle, PostgreSQL, etc. The query needs to be rewritten to achieve the expected result, first find the min(s.from_date) per s.emp_no and at the second step join with e.emp_no to retrieve the needed other fields, as lookups. &lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;PRE&gt;SELECT e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, s.min_from_date
FROM employees e,
(SELECT emp_no, min(from_date) as min_from_date 
FROM new2_salaries
GROUP BY s.emp_no) s
WHERE s.emp_no = e.emp_no;&lt;/PRE&gt;&lt;P&gt;If any of the responses to your question addressed the problem don't forget to vote and accept the answer. If you fix the issue on your own, don't forget to post the answer to your own question. A moderator will review it and accept it.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 10:17:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135299#M39618</guid>
      <dc:creator>cstanca</dc:creator>
      <dc:date>2016-09-06T10:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135300#M39619</link>
      <description>&lt;P&gt;@&lt;A href="https://community.hortonworks.com/users/3486/cstanca.html"&gt; Constantin Stanca&lt;/A&gt; : Thanks a lot for the help but Its is still giving semantic exception Invalid table alias or column reference 's': possible column names are emp_no, salary, from_date, to_date&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 15:21:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135300#M39619</guid>
      <dc:creator>sanjeevanmahaja</dc:creator>
      <dc:date>2016-09-06T15:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135301#M39620</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/2408/sanjeevanmahajan05.html" nodeid="2408"&gt;@sanjeevan mahajan&lt;/A&gt; and &lt;A rel="user" href="https://community.cloudera.com/users/3486/cstanca.html" nodeid="3486"&gt;@Constantin Stanca&lt;/A&gt;.  There is a teeny tiny fix needed to Constantin's last query - the inner query needs to state "Group By emp_no"  instead of "Group By s.emp_no".  This snippet should work:&lt;/P&gt;&lt;PRE&gt;SELECT e.emp_no, e.birth_date,e.first_name, e.last_name, e.gender, s.min_from_date
FROM employees e,
(SELECT emp_no, min(from_date) as min_from_date 
FROM new2_salaries
GROUP BY emp_no) s
WHERE s.emp_no = e.emp_no;&lt;/PRE&gt;&lt;P&gt;By the way - going way back to your original query, this snippet should work as well. Note the changes - using double-quotes around the orc.compress parameters, ensuring that all selected (non-aggregated) columns are in the group by statement, and user the inner join syntax to explicitly call out your join and join clause.  Personal opinion: It's cleaner to keep your join clauses and the where clauses separated... instead of having the join clauses stuffed into the where clause.&lt;/P&gt;&lt;PRE&gt;create table employees2_final 
stored as ORC 
tblproperties ("orc.compress"="SNAPPY") 
AS 
SELECT e.emp_no, e.birth_date, e.first_name, e.last_name, e.gender, 
       min(s.from_date) as `hire_date_new`
from new2_salaries s inner join employees e
   on s.emp_no = e.emp_no 
GROUP BY e.emp_no, e.birth_date, e.first_name, e.last_name, e.gender; 

&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Sep 2016 19:39:56 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135301#M39620</guid>
      <dc:creator>bpreachuk</dc:creator>
      <dc:date>2016-09-06T19:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135302#M39621</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/235/bpreachuk.html" nodeid="235"&gt;@bpreachuk&lt;/A&gt; and &lt;A rel="user" href="https://community.cloudera.com/users/3486/cstanca.html" nodeid="3486"&gt;@Constantin Stanca &lt;/A&gt;Thanks a lot for resolving this.  &lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 21:30:28 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135302#M39621</guid>
      <dc:creator>sanjeevanmahaja</dc:creator>
      <dc:date>2016-09-06T21:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Hive Query not working</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135303#M39622</link>
      <description>&lt;P&gt;&lt;A href="https://community.hortonworks.com/users/235/bpreachuk.html"&gt;@bpreachuk &lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thank you for catching my typo. I wrote the query while on the phone. I voted your addition. Thanks again.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2016 23:38:22 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Hive-Query-not-working/m-p/135303#M39622</guid>
      <dc:creator>cstanca</dc:creator>
      <dc:date>2016-09-06T23:38:22Z</dc:date>
    </item>
  </channel>
</rss>

