/    Sign up×
Community /Pin to ProfileBookmark

MySQL Multi-Table Reference

I’ve got a load of tables within which the records can have a category (identified by the “category_id” field). There’s obviously a “category” table that defines all of these categories, and this is shared by all tables.

Now, if the users wishes to remove a category, I need to check each of the tables to see if it’s ID is used by any of the records. Obviously I could do:

SELECT * FROM event WHERE category_id=’x’;
SELECT *
FROM news WHERE category_id=’x’;
.
.
.
SELECT * FROM quicklinks WHERE category_id=’x’;
SELECT *
FROM quiz WHERE category_id=’x’;

Ad nauseaum, but is there a way of checking if this id is contained within [I]any[/I] of the tables via a single SQL command?

It would be escpecially useful as some of the tables may not exist, each client has their own database with selected tables contained therein.

Any ideas?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Geat 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.19,
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,
)...