0

I have a db model similar to this: Foreign key for multiple tables.

I have account table. An account may be of type venue or band. I decided to make a composite key in account table: id_account | type - together they'd make up a PK (type may be venue or band or their numeric equivalents)

I know how I'd e.g. select all venues with data from account table as well: SELECT account.*, venue.* FROM venue INNER JOIN account ON (venue.id=account.id AND type=venue).

Now, I have an administration panel in which user has his account (which is one of those type - venue or band). When he logs, the panel is different for venue accounts and for bands accounts. Do I need one query to check the type of account (let's say it's venue) and then another query to the venue table to grab his data? Otherwise - can I do something similar to:

SELECT ... FROM IF(type=venue, venue, band)
4

1 回答 1

1

There are several approaches to this. It's probably not too expensive to do the two queries but if you want you could join the 'account' query to both 'band' and 'venue' tables (by some unique ID for either) then take the appropriate column from the result depending on the 'account type' column in the result.

于 2012-09-25T15:56:09.287 回答