I have lots of tables named item1
, item42
, etc. (there are "holes" in the numbering). All tables have the same columns. In particular they have a column called Value
.
How do I retrieve in mySQL the list of all tables for which all their tuples have the same value for Value
?
SELECT Count(Value) FROM item1 GROUP BY Value;
allows to find the number of different values in Value
for a table.
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'myschema'
allows to find all the tables I want to go through.
How do I combine those to get the list of tables for which that count is strictly greater than 2?
(I am not asking whether this database structure is good or bad, it is what it is.)