Re: Delete from right join - Mailing list pgsql-novice

From Josh Berkus
Subject Re: Delete from right join
Date
Msg-id web-2306609@davinci.ethosmedia.com
Whole thread Raw
In response to Delete from right join  ("Chad Thompson" <chad@weblinkservices.com>)
List 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

pgsql-novice by date:

Previous
From: "Chad Thompson"
Date:
Subject: Delete from right join
Next
From: "Brian Johnson"
Date:
Subject: Lost - one sequence