Click to See Complete Forum and Search --> : Search Multiple Tables within Database


NEONecd999
02-21-2007, 02:21 PM
How do I create a MySQL query in PHP that creates an array of rows WHERE id="xx" from multiple tables in a database rather than a single table?

All of the tables I want to search begin with the word "shows" followed by a number.. so for example: shows13, shows17, shows33, etc... The number of tables there are is dynamic, so I'd like it to search any tables that begin with the word "shows"...

Any ideas?

Thanks.

mwmwnmw
02-21-2007, 10:35 PM
You really haven't given enough information to provide a solid answer. The quick and dirty response is that all you have to do is separate the tables by commas ie...

"select * from shows1, shows2, shows3 where id = '17'";

You have to be careful with that one though as it returns a separate row for each matching listing and therefore can get out of hand in terms of result size pretty quickly.

If you are wanting to retrieve specific data from different tables based upon the given id then you probably need a join rather than simply sloughing everything into one big bucket. Not much point in explaining joins in detail here if that's not what you need though.