0

A newbie in sql/ hive...

 SELECT id,seed, day FROM  table_1 WHERE  day = to_date('2016-06-09') limit 5;
302766500   R388899 2016-06-09
692010468   R61140  2016-06-09
662084962   R165803 2016-06-09
1818260515  R411276 2016-06-09
646246322   R426737 2016-06-09


SELECT id, exp, day FROM table_2 WHERE day = to_date('2016-06-09')  limit 5;
OK
2595    e137_1  2016-06-09
2595    e137_2  2016-06-09
4372    e137_1  2016-06-09
7256    e137_1  2016-06-09
18674   e137_1  2016-06-09
Time taken: 1.475 seconds, Fetched: 5 row(s)

As you can see in table 2.. listener id is repeated (2595)..

So, from table 2, I want to find out the distinct ids between two day ranges

and then find the seed of those ids from table 1 between a given date range..

SELECT id, seed FROM table_1 WHERE day = to_date('some date')
JOIN (
SELECT DISTINCT id FROM table_2 WHERE day = to_date('some_date')
) l
ON l.id = id;

But i get this error:

ParseException line 3:0 missing EOF at 'JOIN' near ')'
5
  • are you sure that tag mysql is relevant with your question? Jul 19, 2016 at 20:56
  • maybe not.. I am new in hive.. but everyone has been saying to me, that is sql..
    – frazman
    Jul 19, 2016 at 20:57
  • I suppose, it's Oracle function(to_date) Jul 19, 2016 at 20:57
  • 2
    If you're new in SQL, the first thing you should do is study a tutorial on basic syntax. It's fine to come here for help with logic, but you really should be able to get the order of clauses correct from educational material.
    – Barmar
    Jul 19, 2016 at 21:04
  • @Barmar: yeah.. thats a good suggestion..
    – frazman
    Jul 19, 2016 at 21:09

2 Answers 2

2

seems the where is in wrong position

SELECT table_1.id, table_1.seed FROM table_1 
JOIN (
SELECT DISTINCT id FROM table_2 WHERE day = to_date('some_date')
) l
ON l.id = table_1.id
WHERE table_1.day = to_date('some date')

;
1
  • I am getting this error FAILED: SemanticException [Error 10008]: Line 6:19 Ambiguous table alias 'id' On the join condition line (l.id = id) also, this is hive.. if that helps .
    – frazman
    Jul 19, 2016 at 21:03
1

Join always in the from section:

SELECT id, seed FROM table_1 JOIN (
SELECT DISTINCT id FROM table_2 WHERE day = to_date('some_date')
) l
ON l.id = table_1.id
WHERE day = to_date('some date')
3
  • I am getting this error FAILED: SemanticException [Error 10008]: Line 6:19 Ambiguous table alias 'id' On the join condition line (l.id = id) also, this is hive.. if that helps
    – frazman
    Jul 19, 2016 at 21:03
  • You need to use the table name table_1.id instead of just id
    – Barmar
    Jul 19, 2016 at 21:05
  • yes like he said this erreur appears when you have two table having the same field name like here we have table generated by statement we give it alias L and we have the table_1 both have the same field id so you need to undicate wich table the "id" belong to sorry for my poor english
    – Charif DZ
    Jul 19, 2016 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.