tags:

views:

45

answers:

1

Hi,

i have three mysql tables:

Table 456
id | binder | property1
1 | b | hello
2 | b | goodbye
3 | a | bonjour
Table binder
id | binder | tableid1 | tableid2
1 | a | 23 | 456
2 | b | 21 | 456
3 | c | 45 | 42
Table 21
id | property1 | data..
1 | goodbye | data about goodbye..
2 | ciao | data about ciao..

So first i want to select in binder the binder i need to get the tablesname where data is stored. So i need to select table by a fieldname in this case the fieldname is tableid1 and would have the content 21 so that i have to look in 21. AND it should be property 1 from table 456 and table 21 the same... i am using php and already tried with union and subquerys but it seems that i am to silly to prepare such query!

+5  A: 

Normally if you need these things, you have a serious mistake in your database design. Instead of a table for each type, you need to have a column in your 'data' table the is the type. Of course that is only possible if they have the same type of data in them.

Thirler
okay well.. But how would you structure it better? I prefer to have one table for one 'plugin' ... else i had to merge all in one table with another column for the id of plugin...
rokdd
That last would be correct. If you want to store the same data (as in columns) for all plugins then you should put them in one table. If you want to have different types of columns, you should make specific code/queries that handles each plugin
Thirler
mh well there are different columns for each plugin.. and for me it makes not much sense to store all in one because the querys won't get easier and all plugins can drop everybody! How do you mean with a query for each plugin? when using union i have problem with the different columns.. any other solutions?
rokdd