Re: Selecting records not present in related tables - Mailing list pgsql-sql

From Scott Marlowe
Subject Re: Selecting records not present in related tables
Date
Msg-id 1128629621.29347.242.camel@state.g2switchworks.com
Whole thread Raw
In response to Selecting records not present in related tables  (Hector Rosas <jeziel.rosas@gmail.com>)
List pgsql-sql
On Thu, 2005-10-06 at 14:43, Hector Rosas wrote:
> Hello, I'm trying to select records in a table not present in a
> related table, in example, I've a table with message information
> (subject, message, date, etc) and another (usermessages) with where
> user(s) has that message, its state, etc. Records in this table will
> be deleted in a certain time (just some extra info). 
> I want to select messages records that aren't present in the other
> table (usermessages), I got the next two queries, maybe someone can
> suggest a better one.

A fairly common way to do this is to use a left join and a not null:

select a.id  from tablea a left join tableb b on (a.id=b._aid) where
b._aid IS NULL


pgsql-sql by date:

Previous
From: Frank Bax
Date:
Subject: Re: Selecting records not present in related tables
Next
From: "Anthony Molinaro"
Date:
Subject: Re: Selecting records not present in related tables