Re: Delete from right join

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: "Chad Thompson" <chad(at)weblinkservices(dot)com>, "pgsql-novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Delete from right join
Date: 2003-01-07 20:55:47
Message-ID: web-2306609@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Chad,

> If I do this however
> DELETE
> FROM temp_lol RIGHT JOIN project_lists ON temp_lol.project_id =
> project_lists.project_id
> WHERE temp_lol.project_id Is Null

You can't delete on a JOIN. That would imply that you were deleting
from both tables in a single statement, which is not permitted.

Instead, assuming that you want to delete from temp_lol:

DELETE
FROM temp_lol
WHERE NOT EXISTS (
select project_id FROM project_lists
WHERE temp_lol.project_id = project_lists.project_id );

I'd also suggest picking up a SQL book, such as "SQL Queries for Mere
Mortals" to help you with this kind of stuff.

-Josh Berkus

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Brian Johnson 2003-01-08 04:22:06 Lost - one sequence
Previous Message Chad Thompson 2003-01-07 20:08:29 Delete from right join