Search code examples
sqlhivehql

Hive multiple joins failing


I'm running the following query on hive,

SELECT a, b, c, d, e FROM A JOIN B ON A.a = B.a JOIN C ON A.b = C.a LIMIT 10;

I keep getting the following error,

Error while compiling statement: FAILED: SemanticException Column a Found in more than One Tables/Subqueries

Solution

  • Whenever you have more than one table in a query, qualify all column names:

    SELECT a.a, ?.b, ?.c, ?.d, ?.e 
    FROM A JOIN
         B 
         ON A.a = B.a JOIN
         C 
         ON A.b = C.a
    LIMIT 10;
    

    The ? is for the tables where those columns come from. ALso, it is a bit unorthodox to use LIMIT without an ORDER BY.