Re: Multiple Selects

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Multiple Selects
Дата
Msg-id 13804.968683456@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Multiple Selects  (David Slayton <dslayton@mhsoftware.com>)
Список pgsql-novice
David Slayton <dslayton@mhsoftware.com> writes:
> essentially, i want to select records from the table with one WHERE
> clause, then select a second set from the same table with a different
> WHERE to compose a VIEW.

I think what you are after here is something like

    SELECT *
    FROM mytable AS a, mytable AS b
    WHERE a.f1 = 33 AND b.f2 = 42 AND a.key = b.key ...

Basically, you select from the same table twice, assigning different
aliases to the two entries so that you can distinguish between them
in references from the rest of the query.  I used "a" and "b" here,
but you can use any names you like as table aliases.  The two FROM
entries are then joined just as if they were totally separate tables.

When you just write "SELECT FROM foo", you really get "FROM foo AS foo",
ie, the table's real name is also its alias for that query.

BTW, the "AS" is just a noise word and is often omitted.

            regards, tom lane

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

Предыдущее
От: The Hermit Hacker
Дата:
Сообщение: RE: cat infile | translate all occurences of "NOT NULL" to ""
Следующее
От: patrick.wolf@Aerojet.com (WOLF, PATRICK)
Дата:
Сообщение: RE: Removing all NOT NULL constraints from multiple tabl es easily