Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

How to use NOT IN query in HQL

avatar
New Member

I want to use NOT IN query in HIVE. like this

INSERT INTO TBL2 
SELECT 
   t1.*
FROM
   tbl1 t1
WHERE
  (COl1,COl2,COl3,COl4)
NOT IN
  (
    SELECT 
     COl1,COl2,COl3,COl4
    FROM
     TBL2
) ;

TBL1 is a daily processing data table.TBL2 is a Storage table.

TBL1 and TBL2 are same format tables.

I want to load data that does not exist in TBL 2 to TBL 2 in the daily processing data (TBL1).

How to implement this in hive?

regards.

1 ACCEPTED SOLUTION

avatar
Super Collaborator

I guess you are using HIVE > 0.13, before i am not sure if IN/NOT IN is implemented. But even then, there is this limitation:

  • IN/NOT IN subqueries may only select a single column.

So you might try to append the values into one result column, or you try a left join with a condition like TBL2.COL1 is null

View solution in original post

1 REPLY 1

avatar
Super Collaborator

I guess you are using HIVE > 0.13, before i am not sure if IN/NOT IN is implemented. But even then, there is this limitation:

  • IN/NOT IN subqueries may only select a single column.

So you might try to append the values into one result column, or you try a left join with a condition like TBL2.COL1 is null