Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: how to ?? sql query
Greg Hopkins wrote:
>
> How can I code SQL to do this ??
>
> The table looks like:
>
> Table T
> col C1 col C2
> --------------------
> 101 201
> 102 201
> 102 202
> 103 201
> 103 202
> 103 203
>
> ie, in col C1 there is an ID number, and col C2 is a tag for the ID num.
>
> I want to do something like:
>
> SELECT C1 FROM T WHERE COUNT(C1) = 2
>
> which would return 102 because ID 102 appears twice in column C1.
>
> SELECT C1 FROM T WHERE COUNT(C1) = 3 would return 103 etc.
>
> I started looking at GROUP BY, HAVING etc
>
> Thanks !!!
>
> Please respond to: gregho_at_mosaix.com
Hi!
The SQL code would be
SELECT C1 FROM T
GROUP BY C1
HAVING COUNT(C1) = 2;
...and voilĂ
I hope this helps.
-- CSJ csjean_at_logimens.comReceived on Wed Jan 15 1997 - 00:00:00 CST