From: | Gregory Brauer <greg(at)wildbrain(dot)com> |
---|---|
To: | Joel Burton <joel(at)joelburton(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: SQL over my head... |
Date: | 2002-05-16 21:54:21 |
Message-ID: | 3CE42A8D.7050305@wildbrain.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Joel Burton wrote:
>>-----Original Message-----
>>From: Gregory Brauer [mailto:greg(at)wildbrain(dot)com]
>>Sent: Thursday, May 16, 2002 4:39 PM
>>To: Joel Burton
>>Cc: pgsql-sql(at)postgresql(dot)org
>>Subject: Re: [SQL] SQL over my head...
>>
>>>SELECT F0.id
>>> FROM Foo as F0
>>> JOIN Bar as B0 ON (F0.id=B0.id)
>>> WHERE NOT EXISTS (
>>> (SELECT *
>>> FROM Foo AS F1,
>>> Bar as B1
>>> WHERE ts < CURRENT_TIME
>>> AND F0.attr_a=F1.attr_a
>>> AND F0.attr_b=F1.attr_b
>>> AND B0.attr_a=B1.attr_a
>>> AND B1.ts > B0.ts)
Excellent! This was very close, and put me on the right track.
Here is what ended up working:
SELECT F0.id
FROM Foo as F0
JOIN Bar as B0 ON (F0.bar_id=B0.id)
WHERE NOT EXISTS
(SELECT *
FROM Foo AS F1,
JOIN Bar as B1 ON (F1.bar_id=B1.id)
WHERE B1.ts < CURRENT_TIMESTAMP
AND F0.attr_a=F1.attr_a
AND F0.attr_b=F1.attr_b
AND B0.attr_a=B1.attr_a
AND B1.ts > B0.ts);
There was an extra "(", and it should be CURRENT_TIMESTAMP.
Thanks!
Greg
From | Date | Subject | |
---|---|---|---|
Next Message | Joe Conway | 2002-05-16 22:22:04 | Re: How can I tell the performance difference? |
Previous Message | Josh Berkus | 2002-05-16 21:29:50 | How can I tell the performance difference? |