I have this query
INSERT INTO hist_museum (SELECT * from of_owner.museum al
JOIN (SELECT vd.city_data_id
With "select * from al JOIN ..." you get all values from al and your joined subrequest vd. What you want is
INSERT INTO hist_museum (SELECT al.* from of_owner.museum al
JOIN (SELECT vd.city_data_id
FROM of_owner.city_data vd
WHERE gps_full_date < add_months(SYSDATE,-12)) vd
ON al.city_data_id = VD.city_data_id);
The best-practice when doing an insert
is to list the columns explicitly:
INSERT INTO hist_museum(col1, col2, . . . )
SELECT col1, col2, . . .
FROM of_owner.museum al JOIN
of_owner.city_data vd
ON al.city_data_id = VD.city_data_id
WHERE gps_full_date < add_months(SYSDATE, -12);
Of course, the columns in the SELECT
, should be qualified with the table name.
In addition, the subquery is unnecessary. There is no reason to write a subquery just to filer data.