I have a seemingly basic SQL update to perform on a postgreSQL table that takes values from another table, the table structures are as follows...
sessions_table
session_id (PK)
velocity
time
lengths_table
length_id
session_id
length_dist
I want to update the velocity field with the sum of the length_dist values where session_table.session_id = lengths_table.session_id
I am trying the following statement but get ERROR: null value in column "velocity" violates not-null constraint when I run it (it works fine when I specify a single row)
UPDATE sessions_table
SET velocity = ROUND((SELECT SUM(lengths_table.length_dist)
FROM lengths_table
WHERE lengths_table.session_id = sessions_table.session_id)/time,2)
Can anyone suggest where I am going wrong?
Thanks
David
SELECT SUM(lengths_table.length_dist) FROM lengths. Shouldn't it beFROM lengths_table.