Jack Daniel
Jack Daniel

Reputation: 2611

Exception - Combining two data sets in HiveQL

I am facing Analytics Exception while having inner data sets to be combined.

Query:

Select key,days
    FROM
    (
        Select key          
        FROM sls where id =14004
    ) AS first
    JOIN 
    (
        Select seckey ,days
        FROM
        (
            Select seckey , MAX(opp_days) As days from sls_daily Where id=14004 Group By key
        ) As f
        JOIN
        (
            Select  key,est,cls,days from sls_daily Where dw_cid=14004
        ) As s
        ON f.days = s.days  AND  f.key= s.key
    ) AS second
    ON second.seckey = first.key 

Exception:

AnalysisException: Syntax error in line 15: ) AS first ^ Encountered: FIRST Expected: IDENTIFIER CAUSED BY: Exception: Syntax error

What is the reason for the error.

Upvotes: 0

Views: 26

Answers (1)

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28403

Try to avoid reserved words in SQL.

Try like this

Select `key`,`days`
    FROM
    (
        Select `key`         
        FROM sls where id =14004
    ) AS `first`
    JOIN 
    (
        Select seckey ,`days`
        FROM
        (
            Select seckey , MAX(opp_days) As `days` from sls_daily Where id=14004 Group By key
        ) As f
        JOIN
        (
            Select  `key`,est,cls,`days` from sls_daily Where dw_cid=14004
        ) As s
        ON f.`days` = s.`days`  AND  f.`key`= s.`key`
    ) AS `second`
    ON `second`.seckey = `first`.`key`

Upvotes: 2

Related Questions