On 4.10.2013 15:11, David Johnston wrote: > Ladislav Lenart wrote >> * 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 (...). > > Aliases are mandatory for self-joins. Basically two relations at the same > query level cannot have the same name. With sub-selects the inner level > shields the outer level from being visible so an alias is optional. I > believe the case of a correlated sub-query requires the alias for the same > reason - otherwise you end up with a always true where clause when joining > the supposed two deal tables together. > > There is no right/best way but it is always more clear to rename such that > you avoid repeating the same relation name in the query. I think I understand. Thank you, Ladislav Lenart -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general