I need to update a Table using information from other table. This is my sql query:
UPDATE service a
JOIN agency b USING (feed_id)
SET end_date = (SELECT MIN(start_date)-1
FROM service c
JOIN agency d USING (feed_id)
WHERE b.feed_id = a.feed_+1
AND b.agency_id = d.agency_id)
I need agency id in the condition so the only way is join both table with agency table.
Postgres return:
ERROR: syntax error at or near "JOIN"
LINE 1: UPDATE service a JOIN agency b USING (feed_id) SET end_date ...
Any tips?
create tablestatements for the tables in question, some sample data and the expected result based on that data. Formatted text please, no screen shots