I have a schema with about 3000 tables in a PostgreSQL DB, all having one row with the following columns:
WHERE table_schema = 'schema_A' AND column_name NOT LIKE 'site_id'
GROUP BY table_name;
An easy way would be counting how many times
side_id appears in that table's column listing. If the sum is zero, the table has no
SELECT table_name FROM information_schema.columns WHERE table_schema = 'schema_A' GROUP BY table_name HAVING SUM(CASE WHEN column_name LIKE 'site_id' THEN 1 ELSE 0 END) = 0;
I'm also not sure if it was intentional or not, but
LIKE 'site_id' will have the same effect as
= 'site_id'. If you meant to check if it contains
LIKE '%site_id%' would be more appropriate.