I'm wanting to know if something like this is possible. I'll try to explain this in simplest terms.
Assume I have a database like so:
[tt]
myTable
num type junk
--- ---- ----
1 a abc
1 a xyz
1 b abc
1 c xyz
[/tt]
Now, the query that I'd like to write would pull a list of all num such that it has all 3 types - a, b, and c, ignoring the junk column.
The only way I know to write this query would be like this:
This seems incredibly redundant to me, having to pull 3 subqueries to get all the numbers that exist as all 3 types. I've tried grouping the data with a query similar to this:
This will not work for 2 reasons.
1) the junk column will screw things up
2) if there are multiple instances of the same row (there can be) then it will jack up the count.
Is what I'm wanting to do possible without the subqueries, or is grouping just out of the question? Is it possible to do something like having distinct count(type) = 3 or something of that nature?
-kaht
[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
Assume I have a database like so:
[tt]
myTable
num type junk
--- ---- ----
1 a abc
1 a xyz
1 b abc
1 c xyz
[/tt]
Now, the query that I'd like to write would pull a list of all num such that it has all 3 types - a, b, and c, ignoring the junk column.
The only way I know to write this query would be like this:
Code:
select
num
from
myTable
where
num in (
select num from myTable where type = 'a'
)
and num in (
select num from myTable where type = 'b'
)
and num in (
select num from myTable where type = 'c'
)
)
This seems incredibly redundant to me, having to pull 3 subqueries to get all the numbers that exist as all 3 types. I've tried grouping the data with a query similar to this:
Code:
select
num
from
myTable
group by
num
having
count(*) = 3
1) the junk column will screw things up
2) if there are multiple instances of the same row (there can be) then it will jack up the count.
Is what I'm wanting to do possible without the subqueries, or is grouping just out of the question? Is it possible to do something like having distinct count(type) = 3 or something of that nature?
-kaht
[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]