April 13, 2012
php mysql search through 26 tables
Question by AisRuss
I’ve got this database with about 26 tables (field names are the same in each table) and i was wondering how simple it would be to do a general search on my website based on a keyword which will search through all tables?
Eg Each table has title, author etc etc so if i had a keyword of hairspray – whats the best way to look for the keyword through all tables..
Preferably not through a join or union due to the amount of tables
Cheers in advance
Answer by Starx
Its a very bad way, of creating tables.
If they share a common schema they should be one single table, with some additional field to separate or distinguish the data.
If this is not going to be an option for you, you might want to create a temporary table, which will hold all the data from all 26 tables, then query this table for the search.