From: Scott Marlowe <smarlowe@g2switchworks.com>
To: Hector Rosas <jeziel.rosas@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Selecting records not present in related tables
Date: Thu, 06 Oct 2005 15:13:41 -0500
Message-ID: <1128629621.29347.242.camel@state.g2switchworks.com> (raw)
In-Reply-To: <25266c5c0510061243g13c3f49cudde160c67f961bca@mail.gmail.com>
References: <25266c5c0510061243g13c3f49cudde160c67f961bca@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: smarlowe@g2switchworks.com, jeziel.rosas@gmail.com
Subject: Re: Selecting records not present in related tables
In-Reply-To: <1128629621.29347.242.camel@state.g2switchworks.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox