consulta mysql, disculpen si no es aca donde hay que hacerla

consulta mysql, disculpen si no es aca donde hay que hacerla

Postby goosfancito » Tue Aug 11, 2020 8:51 am

tengo dos tablas:

Code: Select all  Expand view  RUN
tb1: id, codigo1, codigo2, nombre

tb2: id, precio, item


por cada registro de tb1 existe un codigo1 y codigo2 que dependen de "tb2"

Code: Select all  Expand view  RUN
tb2:
id 1
precio $10
item 8

id 2
precio $20
item 1

tb1:
id 1
codigo1 2 (o sea precio $20 e item 1)
codigo2 1 (o sea precio $10 e item 8)


mi pregunta: como se haria la consulta? para que traiga todos los datos?
Code: Select all  Expand view  RUN
#define consulta;
"SELECT "+;
"tb1.id          as c1, " +;
"tb1.codigo1 as c2, " +;
"tb1.codigo2 as c3, " +;
"tb2.id          as c4, "+;
"tb2.precio   as c5, "+;
"tb2.item      as c6" +;
"SELECT tb1 " +;
"LEFT JOIN tb2 on tb1.codigo1 = tb2.id " .....

y hasta aca llego, porque no se como hacer el left join para "tb1.codigo2 = tb2.id"

gracias.
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: consulta mysql, disculpen si no es aca donde hay que hacerla

Postby Francisco Horta » Tue Aug 11, 2020 3:31 pm

Goosfancito,

yo lo hago asi:

SELECT mov.*,articulos.receta, articulos.costopromedio, articulos.idalmacen_s
FROM movimientos mov
LEFT OUTER JOIN ventas ON mov.idticket = ventas.id
LEFT OUTER JOIN articulos ON mov.id = articulos.id
WHERE ventas.corte = '0' ORDER BY id,orden

ya nomas lo adaptas al tuyo,

saludos
____________________
Paco
Francisco Horta
 
Posts: 845
Joined: Sun Oct 09, 2005 5:36 pm
Location: la laguna, mexico.

Re: consulta mysql, disculpen si no es aca donde hay que hacerla

Postby goosfancito » Tue Aug 11, 2020 6:51 pm

gracias
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: consulta mysql, disculpen si no es aca donde hay que hacerla

Postby nageswaragunupudi » Wed Aug 12, 2020 2:06 pm

Code: Select all  Expand view  RUN
TEXT INTO cSql
   SELECT tb1.id as ID, tb1.code1 as CODE1, tb1.code2 as CODE2,
          tb2a.id as ID1, tb2a.price as PRICE1, tb2a.item as ITEM1,
          tb2b.id as ID2, tb2b.price as PRICE2, tb2b.item as ITEM2
   FROM tb1
   LEFT OUTER JOIN tb2 AS tb2a ON tb1.code1 = tb2a.id
   LEFT OUTER JOIN tb2 AS tb2b ON tb1.code2 = tb2b.id
ENDTEXT
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: consulta mysql, disculpen si no es aca donde hay que hacerla

Postby goosfancito » Wed Aug 12, 2020 3:38 pm

thank's
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 55 guests