una consulta sobre SELECT

14/10/2008 - 18:39 por Luis Mata | Informe spam
Hola

tengo esto

codarticul,sum(cantidad) as cantidad from archtra3 where coidtalm = '10'
group by codarticul
union all
select codart,sum(cantir) as cantidad from sidetali where coidtalm = '10'
group by codart

pero ahi hay 2 tablas y hay codigos duplicados en el primer campo.

como puedo hacer para que en estos 2 select haya valores unicos?

Luis

Preguntas similare

Leer las respuestas

#1 Maxi Accotto
15/10/2008 - 00:51 | Informe spam
Depende que quieras hacer con los duplicados, si no los quieres mostrar
(tampoco que no los sume) entonces no uses UNION ALL y si usa UNION solo.

Si los queres ademas sumar y que muestre uno solo entonces

select codarticul,sum(cantidad) as cant from

(
select codarticul,sum(cantidad) as cantidad from archtra3 where coidtalm =
'10'
group by codarticul
union all
select codart,sum(cantir) as cantidad from sidetali where coidtalm = '10'
group by codart
) t

group by codarticul


Saludos
Maxi Accotto
Microsoft MVP en SQLServer
SQltotalconsulting
-

"Luis Mata" escribió en el mensaje de
noticias:#
Hola

tengo esto

codarticul,sum(cantidad) as cantidad from archtra3 where coidtalm = '10'
group by codarticul
union all
select codart,sum(cantir) as cantidad from sidetali where coidtalm = '10'
group by codart

pero ahi hay 2 tablas y hay codigos duplicados en el primer campo.

como puedo hacer para que en estos 2 select haya valores unicos?

Luis
Respuesta Responder a este mensaje
#2 Luis Mata
15/10/2008 - 20:01 | Informe spam
Perfecto me sirvio mucho, Gracias

"Maxi Accotto" escribió en el mensaje de
noticias news:
Depende que quieras hacer con los duplicados, si no los quieres mostrar
(tampoco que no los sume) entonces no uses UNION ALL y si usa UNION solo.

Si los queres ademas sumar y que muestre uno solo entonces

select codarticul,sum(cantidad) as cant from

(
select codarticul,sum(cantidad) as cantidad from archtra3 where coidtalm =
'10'
group by codarticul
union all
select codart,sum(cantir) as cantidad from sidetali where coidtalm = '10'
group by codart
) t

group by codarticul


Saludos
Maxi Accotto
Microsoft MVP en SQLServer
SQltotalconsulting
-

"Luis Mata" escribió en el mensaje de
noticias:#
Hola

tengo esto

codarticul,sum(cantidad) as cantidad from archtra3 where coidtalm = '10'
group by codarticul
union all
select codart,sum(cantir) as cantidad from sidetali where coidtalm = '10'
group by codart

pero ahi hay 2 tablas y hay codigos duplicados en el primer campo.

como puedo hacer para que en estos 2 select haya valores unicos?

Luis



email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida