Re: Why does this SQL work?

Поиск
Список
Период
Сортировка
От Victor Yegorov
Тема Re: Why does this SQL work?
Дата
Msg-id CAGnEbojvNhei9qGhB4GTbgytAOhkD6rKZK+a=gS22qsz4DameQ@mail.gmail.com
обсуждение исходный текст
Ответ на Why does this SQL work?  (Anil Menon <gakmenon@gmail.com>)
Ответы Re: Why does this SQL work?
Список pgsql-general
2015-05-11 19:26 GMT+03:00 Anil Menon <gakmenon@gmail.com>:
manualscan=> select count(*) From public.msgtxt where msgid in (select msgid From ver736.courier where org_id=3);
 count
-------
 10225
(1 row)

Please note, there is no msgid col in courier table. Which brings the question why does this SQL work? An "select msgid From courier where org_id=3" by itself gives error column "msgid" does not exist.

Because you can reference both, inner and outer columns from the inner query.
Here you're most likely referring to the outer `msgid` in the subquery.

That's why it is always a good idea to prefix all your columns with tables aliases.


--
Victor Y. Yegorov

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

Предыдущее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: Why does this SQL work?
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: RPM building tools and info missing?