| From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
|---|---|
| To: | PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org> |
| Subject: | correlated subquery |
| Date: | 1999-12-29 22:36:39 |
| Message-ID: | 199912292236.RAA13960@candle.pha.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Is this a good example of a required correlated subquery:
SELECT f1.firstname, f1.lastname, f1.age
FROM friends f1
WHERE age = (
SELECT MAX(age)
FROM friends f2
WHERE f1.state = f2.state
)
ORDER BY firstname, lastname
It finds the oldest person in each state. HAVING can't do that, right?
--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Adriaan Joubert | 1999-12-29 23:10:14 | Re: [HACKERS] Index corruption |
| Previous Message | Jan Wieck | 1999-12-29 22:25:57 | Re: [HACKERS] Index corruption |