[Q] Table aliasing

Поиск
Список
Период
Сортировка
От Ladislav Lenart
Тема [Q] Table aliasing
Дата
Msg-id 524E9F84.8000603@volny.cz
обсуждение исходный текст
Ответы Re: [Q] Table aliasing  (Adam Jelinek <ajelinek@gmail.com>)
Re: [Q] Table aliasing  (David Johnston <polobo@yahoo.com>)
Список pgsql-general
Hello.

I have a noob question about table aliases in SQL.

Suppose the following query:

SELECT *
FROM deal
WHERE
    deal.id IN (
        SELECT DISTINCT deal.id
        FROM
            deal
            JOIN partner_share ON deal.id = partner_share.deal_id
            JOIN partner ONshare.partner_id = partner.id
        WHERE
            partner.team_id = 12345
            AND (
                partner_share.type = 1 AND deal.external_id IS NOT NULL
                OR partner_share.type = 2 AND deal.external_id IS NULL
            )
    )

As you can see, the IN (...) references the deal table too.

My questions:
* Should I alias one of the references to deal?
* The above query works the same both with and without an alias, so is it simply
a matter of taste / good practice?
* Where can I find more info about this, i.e. when the alias is mandatory and
when it is only a convenience? I've scanned through

    http://www.postgresql.org/docs/9.1/static/queries-table-expressions.html

but it only mentions that subselect in FROM must have an alias. I would like to
know about IN (...) and EXISTS (...).


Thank you,

L.



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

Предыдущее
От: Rémi Cura
Дата:
Сообщение: Re: [GENERAL] Re: [GENERAL] Help on ṕerformance
Следующее
От: Adam Jelinek
Дата:
Сообщение: Re: [Q] Table aliasing