Oracle: How to get max value for each item in list
<p>I have a very large table that I need to retrieve data from. The table looks like this:</p>

<pre><code>A        B            C        D
1        foo          4        q
1        fool         2        p
1        fools        13       a
2        pho          5        d
3        phone        14       g
3        phones       6        f
</code></pre>

<p>I'm trying to run something like:</p>

<pre><code>select max(B) from table where A = 1 union
select max(B) from table where A = 2 union
.
.
.
select max(B) from table where A = 50000;
</code></pre>

<p>What I want is to get:</p>

<pre><code>1 -&gt; fools
2 -&gt; pho
3 -&gt; phones
</code></pre>

<p>I have about 50,000 records to run this query for.
This above approach theoretically works (I tried on a small subset), but I think it's inefficient to have one select query for each of the 50000 values.
This also resulted in a process out of memory error.</p>

<p>Is there a way I can run this in a single query? 
I tried:</p>

<pre><code>select max(B) from table where A in (first group of 1000) union
select max(B) from table where A in (1000...2000) union
.
.
.
select max(B) from table where A in (40000...50000)
</code></pre>

<p>But this gives me only one max value per select query (and I understand why)
What I really want is 50000 max values.</p>

<p>Is there a way for me to get the value of max(B) for each item in the list if I use </p>

<pre><code>select max(B) from table where A in (...)
</code></pre>

<p>Thank you!</p>