SQL query : how to check existence of multiple rows with one query
<p>I have this table <code>MyTable</code>:</p>

<pre><code>PROG    VALUE
-------------
1       aaaaa
1       bbbbb
2       ccccc
4       ddddd
4       eeeee
</code></pre>

<p>now I'm checking the existence of a tuple with a certain id with a query like</p>

<pre><code>SELECT COUNT(1) AS IT_EXISTS
FROM MyTable
WHERE ROWNUM = 1 AND PROG = {aProg}
</code></pre>

<p>For example I obtain with aProg = 1 :</p>

<pre><code>IT_EXISTS
---------
   1
</code></pre>

<p>I get with aProg = 3 :</p>

<pre><code>IT_EXISTS
---------
   0
</code></pre>

<p>The problem is that I must do multiple queries, one for every value of PROG to check.</p>

<p>What I want is something that with a query like </p>

<pre><code>SELECT PROG, ??? AS IT_EXISTS
FROM MyTable
WHERE PROG IN {1, 2,3, 4, 5} AND {some other condition}
</code></pre>

<p>I can get something like </p>

<pre><code>PROG     IT_EXISTS
------------------
   1        1
   2        1
   3        0
   4        1
   5        0
</code></pre>

<p>The database is Oracle...</p>

<p>Hope I'm clear</p>

<p>regards </p>

<p>Paolo</p>