I currently have 2 queries that return
PRODUCER FirstQueryColumn
------------------------------ ----------------------
aaaaaaaaaaaa 1
bbbbbbbbbbb 1
PRODUCER SecondQueryColumn
------------------------------ ----------------------
aaaaaaaaaaaa 2
bbbbbbbbbbb 1
What I'd like to know is how should I go about making it such that I can have in a single query the same data, that is, I want something that'll yield (Producer, FirstQueryColumn, SecondQueryColumn)
.
How can I do that?
Here are my current queries:
select Producers.name Prod, count(Animals.idanimal) AnimalsBought
from AnimalsBought, Animals, Producers
where (AnimalsBought.idanimal = Animals.idanimal) and (Animals.owner = Producers.nif) group by Producers.name;
select Producers.name Prod, count(Animals.idanimal) AnimalsExploration
from AnimalsExploration, Animals, Producers
where (AnimalsExploration.idanimal = Animals.idanimal) and (Animals.owner = Producers.nif) group by Producers.name;
As you can see, for this case a join will not do much:
select Producers.name Prod, count(AnimalsBought.idanimal) AnimalsBought, count(AnimalsExploration.idanimal) AnimalsExploration
from Producers, Animals, AnimalsBought, AnimalsExploration
where (AnimalsExploration.idanimal = Animals.idanimal) and (Animals.owner = Producers.nif) group by Producers.name;
or am I doing something wrong?
See Question&Answers more detail:os