0

I am trying to update the column 'lt_dispatch_level' in my table "inland" with the values from another table "current_obs" that has a corresponding column 'lt_dispatch_level'. However when I run this SQL query:

INSERT INTO inland (lt_dispatch_level, timestamp) SELECT lt_dispatch_level, timestamp FROM current_obs;

I get the values from current_obs added in as a second row, with null values being aded in the first row. I attached an image of what this looks like.

enter image description here

What do I need to change in my SQL query to get my values in the first row?

1

You have to use Update query, something like below,

UPDATE inland
SET lt_dispatch_level = current_obs.lt_dispatch_level,
  timestamp = current_obs.timestamp
FROM current_obs
WHERE current_obs.{common column} = inland.{common column}
AND inland.cartodb_id= 1
  • This query is not working for me and I can't figure out why. Do I need to fill in a matching column name in the {}s? I have matching columns in both tables (lt_dispatch_level, timestamp) and the table names are correct. – cbunn Aug 12 '14 at 16:07
  • Nevermind that, I just solved it by creating a matching column in my current_obs table. Thank you for your help! – cbunn Aug 12 '14 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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