elektrongyorsito via DBMonster.com
2007-02-02 07:27:26 UTC
Hello,
I have 3 tables:
T_component =TCO
cmp_id | name
1 | door
2 | exhaust
T_cmp_cat =TCC (categories and components)
id | cmp_id | cat_id
1 | 1 | 1
2 | 1 | 3
3 | 1 | 4
4 | 2 | 1
5 | 2 | 2
T_categories =TCA
cat_id | cat_name
1 | car
2 | motorcycle
3 | train
4 | airplane
5 | other
If I ask this:
select name,cat_name from TCO inner join TCC on TCO.cmp_id=TCC.cmp_id inner
join TCA on TCA.cat_id=TCC.cat_id
then I get, like this:
name | cat_name
door | car
door | train
door | airplane
exhaust |car
exhaust |motorcycle
But, I would like to get this:
Name | cat_car | cat_motorcycle | cat_train | cat_airplane | cat_other
door | 1 | 0 | 1 | 1 | 0
exhaust | 1 | 1 | 0 | 0 | 0
Is there any simple way to get?
When I created the db, I asked more poeple about this, and they suggested
this form, because flexible expanding of the categories. But now I think I
could work easier if I store the categories into the component table, like
this:
T_component =TCO
cmp_id | name | cat1 | cat2 ...
1 | door | 0 | 1 |...
2 | exhaust | 1 | 1 |...
But it displease me... How can I solve it correctly? Thank you
I have 3 tables:
T_component =TCO
cmp_id | name
1 | door
2 | exhaust
T_cmp_cat =TCC (categories and components)
id | cmp_id | cat_id
1 | 1 | 1
2 | 1 | 3
3 | 1 | 4
4 | 2 | 1
5 | 2 | 2
T_categories =TCA
cat_id | cat_name
1 | car
2 | motorcycle
3 | train
4 | airplane
5 | other
If I ask this:
select name,cat_name from TCO inner join TCC on TCO.cmp_id=TCC.cmp_id inner
join TCA on TCA.cat_id=TCC.cat_id
then I get, like this:
name | cat_name
door | car
door | train
door | airplane
exhaust |car
exhaust |motorcycle
But, I would like to get this:
Name | cat_car | cat_motorcycle | cat_train | cat_airplane | cat_other
door | 1 | 0 | 1 | 1 | 0
exhaust | 1 | 1 | 0 | 0 | 0
Is there any simple way to get?
When I created the db, I asked more poeple about this, and they suggested
this form, because flexible expanding of the categories. But now I think I
could work easier if I store the categories into the component table, like
this:
T_component =TCO
cmp_id | name | cat1 | cat2 ...
1 | door | 0 | 1 |...
2 | exhaust | 1 | 1 |...
But it displease me... How can I solve it correctly? Thank you
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/mysql-general/200702/1
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/mysql-general/200702/1