Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Subquery help with Max !
"April" <privateBenjamin_at_hushmail.com> wrote news:6effef59.0202251520.661b1894_at_posting.google.com...
> I have a table like this:
>
> Paymentkey PaymentYear PaymentMonth
> 1 2001 1
> 1 2000 2
> 1 2000 6
> 1 2002 12
> 2 2003 1
> 2 2004 6
> 3 2002 3
>
> I want to retrieve the lowest PaymentYear AND PaymentMonth for a
> particular PaymentKey. For example, Paymentkey1 should return
> PaymentYear(2000),PaymentMonth(2).
>
> How can I get this to work?!
Hi April,
have a look at this:
SELECT a.year, a.month
FROM t1 a
WHERE key=1
AND year=(SELECT MIN(year)
FROM t1 WHERE key=1) AND month=(select MIN(month) FROM t1 WHERE key=1 AND year=(SELECT MIN(year) FROM t1 WHERE key=1));
I hope, this is what you're looking for.
Regards,
Guido
Received on Tue Feb 26 2002 - 01:26:02 CST