I’m trying to select all tables from a specified database that contain columns ‘lang’ and ‘project’. This is what i’m doing:
SELECT DISTINCT(ISC1.TABLE_NAME) AS `table` FROM INFORMATION_SCHEMA.COLUMNS AS ISC1
JOIN INFORMATION_SCHEMA.COLUMNS AS ISC2 ON
(ISC1.TABLE_SCHEMA=ISC2.TABLE_SCHEMA AND ISC1.TABLE_NAME=ISC2.TABLE_NAME AND ISC2.COLUMN_NAME='project')
WHERE ISC1.COLUMN_NAME='lang' AND ISC2.COLUMN_NAME='project' AND ISC1.TABLE_SCHEMA='some_database'
- It does work, but i have a feeling it is a bad way to write this kind of query. If someone can improve on it, that would be nice.
- Now i have to change this query to select all tables that have ‘lang’ column, but do NOT have ‘project’ column. And honestly i can’t figure out where to start…
Thanks for your help
Without project column :