pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Denilson Guedes Duarte <denilson@bnet.com.br>
To: pgsql-admin@postgresql.org
Subject: Problems in query
Date: Sat, 25 May 2002 09:53:39 -0300
Message-ID: <001701c203eb$31173e80$0a01010a@bnet.com.br> (raw)


I have this query:

select c.cod_cliente, c.controle, c.dt_vencimento, c.dt_emissao, c.nro_doc_banco, 
c.nro_documento, c.recebido, c.ref_cidade, c.valor, 
(select u.username from ctareceber c left join username u on u.id=c.cod_cliente limit 1) as fldusername, p.id, p.nome, a.id, a.nome from (((ctareceber c left join username u on u.id=c.cod_cliente) left join pessoas p on p.id=c.cod_cliente) left join auxcidades a on a.id=c.ref_cidade) where c.dt_recebimento>='01/05/2002' and c.dt_recebimento<='23/05/2002' and c.recebido='S'

and runs ok, but the problem is that the table username (alias u) hane N records and I want to get only one record. I try to use a subqyuery:
select ....
(select u.username from ctareceber c left join username u on u.id=c.cod_cliente limit 1) as fldusername
.....
in this case the query run ok, but I lose the left join property.

How I can to do run with left join and get only one record in the other table (username u) ?


Denilson Guedes Duarte
Provedor de Internet da Fronteira Oeste Ltda - ISPbnet
Fone: (55) 411 6558
Cel.:  (55) 9973 0219
Email: denilson@bnet.com.br
ICQ: 14319874

view thread (3+ messages)  latest in thread

Message-ID: <001701c203eb$31173e80$0a01010a@bnet.com.br>
Permalink:  ../001701c203eb$31173e80$0a01010a@bnet.com.br/
Also on:    postgresql.org/message-id/001701c203eb$31173e80$0a01010a@bnet.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: denilson@bnet.com.br
  Subject: Re: Problems in query
  In-Reply-To: <001701c203eb$31173e80$0a01010a@bnet.com.br>
  References: <001701c203eb$31173e80$0a01010a@bnet.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox