/    Sign up×
Community /Pin to ProfileBookmark

Search Multiple Tables within Database

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.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@mwmwnmwFeb 22.2007 — 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.
×

Success!

Help @NEONecd999 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...