0

I'm trying to insert into a table column data from another table column in SQL.

For example:

TABLE A: ID, COD_LOC, IMP_TOT

TABLE B: ID, SUP, IMP_TOT

In table B I've the column IMP_TOT filled with NULL. I want to insert the data from tableA.IMP_TOT to tableB.IMP_TOT where A.ID=B.ID.

How can I do that in SQL?

thank you for time

3
  • 1
    I removed the incompatible database tags. Please tag with the database you are really using. Commented Jun 23, 2017 at 11:26
  • you want update the column imp_tot in table B with the corresponding value in table A .? .. which db you are using? Commented Jun 23, 2017 at 11:28
  • I'm using Hive, thank you. Commented Jun 26, 2017 at 8:43

1 Answer 1

1

Try something like this:

UPDATE tableB SET IMP_TOT = ( SELECT IMP_TOT FROM tableA WHERE ID = tableB.ID )

Edit

MERGE INTO tableB USING tableA ON tabelA.ID = tableB.ID
WHEN MATCHED THEN UPDATE SET IMP_TOT = tableA.IMP_TOT
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Thank you for your response. I'm using Hive and it doesnt recognize de sentence :(

Your Answer

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