Re: Selecting records not present in related tables

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: Selecting records not present in related tables
Дата
Msg-id 1128629621.29347.242.camel@state.g2switchworks.com
обсуждение исходный текст
Ответ на Selecting records not present in related tables  (Hector Rosas <jeziel.rosas@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Frank Bax
Дата:
Сообщение: Re: Selecting records not present in related tables
Следующее
От: "Anthony Molinaro"
Дата:
Сообщение: Re: Selecting records not present in related tables