From denilson@bnet.com.br Sat May 25 12:52:27 2002 Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 761044760A4 for ; Sat, 25 May 2002 08:52:27 -0400 (EDT) Received: from ns2.bnet.com.br (unknown [200.180.215.4]) by postgresql.org (Postfix) with ESMTP id 57175475D8F for ; Sat, 25 May 2002 08:45:10 -0400 (EDT) Received: from Denilson ([200.180.215.5]) by ns2.bnet.com.br (8.11.4/8.11.0) with SMTP id g4PCwuE24793 for ; Sat, 25 May 2002 09:58:56 -0300 Message-ID: <001701c203eb$31173e80$0a01010a@bnet.com.br> From: "Denilson Guedes Duarte" To: Subject: Problems in query Date: Sat, 25 May 2002 09:53:39 -0300 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0014_01C203D2.0B97ABE0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Archive-Number: 200205/208 X-Sequence-Number: 4383 This is a multi-part message in MIME format. ------=_NextPart_000_0014_01C203D2.0B97ABE0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable I have this query: select c.cod_cliente, c.controle, c.dt_vencimento, c.dt_emissao, c.nro_doc_= banco,=20 c.nro_documento, c.recebido, c.ref_cidade, c.valor,=20 (select u.username from ctareceber c left join username u on u.id=3Dc.cod_c= liente limit 1) as fldusername, p.id, p.nome, a.id, a.nome from (((ctareceb= er c left join username u on u.id=3Dc.cod_cliente) left join pessoas p on p= .id=3Dc.cod_cliente) left join auxcidades a on a.id=3Dc.ref_cidade) where c= .dt_recebimento>=3D'01/05/2002' and c.dt_recebimento<=3D'23/05/2002' and c.= recebido=3D'S' and runs ok, but the problem is that the table username (alias u) hane N re= cords 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=3Dc.cod_c= liente 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 tab= le (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 ------=_NextPart_000_0014_01C203D2.0B97ABE0 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
 
I have this query:
 
select c.cod_cliente, c.controle, c.dt_ven= cimento,=20 c.dt_emissao, c.nro_doc_banco,
c.nro_documento, c.recebido, c.ref_cidad= e,=20 c.valor,
(select u.username from ctareceber c left join username u on= =20 u.id=3Dc.cod_cliente limit 1) as fldusername, p.id, p.nome, a.id, a.nome fr= om=20 (((ctareceber c left join username u on u.id=3Dc.cod_cliente) left joi= n=20 pessoas p on p.id=3Dc.cod_cliente) left join auxcidades a on a.id=3Dc.ref_c= idade)=20 where c.dt_recebimento>=3D'01/05/2002' and c.dt_recebimento<=3D'23/05= /2002'=20 and c.recebido=3D'S'
 
and runs ok, but the problem is that the t= able=20 username (alias u) hane N records and I want to get only one record. I try = to=20 use a subqyuery:
select ....
(select u.username from ctareceber c left = join=20 username u on u.id=3Dc.cod_cliente limit 1) as fldusername
.....
in this case the query run ok, but I lose = the left=20 join property.
 
How I can to do run with left join and get= only one=20 record in the other table (username u) ?
 
 
Denilson Guedes Duarte
Provedor de Inte= rnet da=20 Fronteira Oeste Ltda - ISPbnet
Fone: (55) 411 6558
Cel.:  (55) 9= 973=20 0219
Email: denilson@bnet.com.br
ICQ:=20 14319874
------=_NextPart_000_0014_01C203D2.0B97ABE0-- From rk73@sea.plala.or.jp Wed May 29 12:17:06 2002 Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 03D15475931 for ; Wed, 29 May 2002 08:17:06 -0400 (EDT) Received: from mps3.plala.or.jp (mpsb-nat18.plala.or.jp [202.212.115.65]) by postgresql.org (Postfix) with ESMTP id 93596475910 for ; Wed, 29 May 2002 08:17:00 -0400 (EDT) Received: from vip1600 ([218.47.117.179]) by mps3.plala.or.jp with ESMTP id <20020529121702.YEZO9425.mps3.plala.or.jp@vip1600>; Wed, 29 May 2002 21:17:02 +0900 Date: Wed, 29 May 2002 21:17:26 +0900 From: Masaru Sugawara To: "Denilson Guedes Duarte" Subject: Re: Problems in query Cc: pgsql-admin@postgresql.org In-Reply-To: <001701c203eb$31173e80$0a01010a@bnet.com.br> References: <001701c203eb$31173e80$0a01010a@bnet.com.br> Message-Id: <20020529204154.7872.RK73@sea.plala.or.jp> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Becky! ver. 2.00.11 X-Archive-Number: 200205/245 X-Sequence-Number: 4420 On Sat, 25 May 2002 09:53:39 -0300 "Denilson Guedes Duarte" wrote: > 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) ? > I'm not sure what the problems is. Could you show us the output of the result you hope ? Regards, Masaru Sugawara From rk73@sea.plala.or.jp Wed May 29 15:37:15 2002 Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 080EF47585D for ; Wed, 29 May 2002 11:37:15 -0400 (EDT) Received: from mps2.plala.or.jp (mpsb-nat02.plala.or.jp [202.212.114.145]) by postgresql.org (Postfix) with ESMTP id B2B464750F5 for ; Wed, 29 May 2002 11:37:13 -0400 (EDT) Received: from vip1600 ([218.47.117.179]) by mps2.plala.or.jp with ESMTP id <20020529153717.FVTJ25092.mps2.plala.or.jp@vip1600>; Thu, 30 May 2002 00:37:17 +0900 Date: Thu, 30 May 2002 00:37:41 +0900 From: Masaru Sugawara To: "Denilson Guedes Duarte" Subject: Re: Problems in query Cc: pgsql-admin@postgresql.org In-Reply-To: <20020529204154.7872.RK73@sea.plala.or.jp> References: <001701c203eb$31173e80$0a01010a@bnet.com.br> <20020529204154.7872.RK73@sea.plala.or.jp> Message-Id: <20020530001107.8D7D.RK73@sea.plala.or.jp> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Becky! ver. 2.00.11 X-Archive-Number: 200205/249 X-Sequence-Number: 4424 On Wed, 29 May 2002 10:54:50 -0300 "Denilson Guedes Duarte" wrote: Probably this runs, I guess. As for username table, however, I have another question: why denilson is first. What rule there would be ? select c1.cod_cliente, c1.controle, c1.dt_vencimento, c1.dt_emissao, c1.nro_doc_banco, c1.nro_documento, c1.recebido, c1.ref_cidade, c1.valor, (select u0.username from username u0 where u0.id = c1.cod_cliente limit 1) as fldusername, p1.id, p1.nome, a1.id, a1.nome from (select c0.* from ctareceber c0 where c0.recebido = 'S' and c0.dt_recebimento >= '01/05/2002' and c0.dt_recebimento <= '23/05/2002') c1 left join username u1 on (u1.id = c1.cod_cliente) left join pessoas p1 on (p1.id = c1.cod_cliente) left join auxcidades a1 on (a1.id = c1.ref_cidade) Regard, Masaru Sugawara > ok, > table ctareceber: > cod_cliente int 4 20 > document varchar 8 NF > factura int 4 000001 > ... > > > table cliente: > cod_cliente int 4 20 > name varchar 60 Company International > > > table username: > cod_cliente int 4 20 20 20 > 20 > username varchar 8 denilson deni2 deni3 deni4 > > in this table have more then one record for client id "20" > > I want to do: > > print the records from table ctareceber, showing the name of client and the > first username too. like this: > > Factura Client Username > ------------ --------------------------- ----------- > NF 000001 20 Company International denilson > > I used left join because the client it has none record in table username. > > > ----- Original Message ----- > From: "Masaru Sugawara" > To: "Denilson Guedes Duarte" > Cc: > Sent: Wednesday, May 29, 2002 9:17 AM > Subject: Re: [ADMIN] Problems in query > > > On Sat, 25 May 2002 09:53:39 -0300 > "Denilson Guedes Duarte" wrote: > > > > 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) ? > > > > > I'm not sure what the problems is. > Could you show us the output of the result you hope ? > > > Regards, > Masaru Sugawara > >