Is it possible to use the contents of a field in one table to reference a field name in another. For example
T1
ID RefName Description
1 f1 Fruit
2 f2 Chocolate
3 f3 Coffee
etc...
T2
ID f1 f2 f3
1 a a b
2 b b a
3 b c b
etc...
my SQL statement should be something like
SELECT RefName
(SELECT count("f1") from t2 where f1='a'),
(SELECT count("f1") from t2 where f1='b'),
(SELECT count("f1") from t2 where f1='c')
from t1
The "f1" should change for each row so that I can count column f1, f2 and f3 per row
The results should look like this
CategoryA CategoryB CategoryC
Fruit 1 2 0
Chocolate 1 1 1
Coffee 1 2 0
Thanks in advance for any help.
T1
ID RefName Description
1 f1 Fruit
2 f2 Chocolate
3 f3 Coffee
etc...
T2
ID f1 f2 f3
1 a a b
2 b b a
3 b c b
etc...
my SQL statement should be something like
SELECT RefName
(SELECT count("f1") from t2 where f1='a'),
(SELECT count("f1") from t2 where f1='b'),
(SELECT count("f1") from t2 where f1='c')
from t1
The "f1" should change for each row so that I can count column f1, f2 and f3 per row
The results should look like this
CategoryA CategoryB CategoryC
Fruit 1 2 0
Chocolate 1 1 1
Coffee 1 2 0
Thanks in advance for any help.