Table2 has a column with values containing column names in table1. I want to remove any entries in table2 where the actual column name in table1 does not exist. This is the general idea but apparently isn't the proper approach so how can it be done?
DELETE FROM table2
WHERE ID IN (SELECT
ID
FROM table2
WHERE FormID = 2
AND FieldName NOT IN (SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'db_name'
AND TABLE_NAME = 'table1'))