Re: subselect and left join not working?
От | Jasen Betts |
---|---|
Тема | Re: subselect and left join not working? |
Дата | |
Msg-id | icvsmc$6p1$1@reversiblemaps.ath.cx обсуждение исходный текст |
Ответ на | subselect and left join not working? (Jorge Arenas <jorge.arenas@kamarble.com>) |
Ответы |
Re: subselect and left join not working?
|
Список | pgsql-sql |
On 2010-11-29, Jorge Arenas <jorge.arenas@kamarble.com> wrote: > select zona_id from zonas where zona_id not in (select zona_id from usuarios ####### ####### ####### > where per_id =2) select 'FRED' from from usuarios where per_id =2 what'shappening is your not in subquery is being 'corrupted' by the surrounding query, the expression zona_id is being replaced with the value from the main query. so the inner query return multiple copies of the value from the outer query and the not-in fails. to avoid that confusion do it this way: select zona_id as z from zonas where z not in (select zona_id fromusuarios where per_id =2) or this way: select zona_id from zonas where zona_id not in (select usuarios.zona_id fromusuarios where per_id =2) or this way: select zona_id from zonas where zona_id not in (select u.zona_id fromusuarios as u where per_id =2) -- ⚂⚃ 100% natural
В списке pgsql-sql по дате отправления: