Re: References NULL field

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: References NULL field
Дата
Msg-id 20060403035722.GA48847@winnie.fuhr.org
обсуждение исходный текст
Ответ на References NULL field  (Paul M Foster <paulf@quillandmouse.com>)
Список pgsql-sql
On Sun, Apr 02, 2006 at 11:43:34PM -0400, Paul M Foster wrote:
> I want to do a query (in PHP, FWIW) that returns all the fields in
> registrars, and the contents of any relevant notes records, or null for
> those fields if there is no corresponding record in the notes table. But
> when I do
> 
> SELECT * FROM registrars, notes WHERE regname = 'blah'
> 
> no matter that I put after the 'blah' (or nothing), I get no results. As
> soon as I add notes into the tables being queried, I get nothing.

The above query does a cross (cartesian) join of registrars and
notes.  Since notes is empty the join result is empty.  Try an
outer join:

SELECT *
FROM registrars LEFT OUTER JOIN notes USING (note_id)
WHERE regname = 'blah';

-- 
Michael Fuhr


В списке pgsql-sql по дате отправления:

Предыдущее
От: Paul M Foster
Дата:
Сообщение: References NULL field
Следующее
От: Bryce Nesbitt
Дата:
Сообщение: Re: group by function, make SQL cleaner?