Comments - What Join

11 years, 5 months ago Richard Couture

After hours of wrestling with this I came up with something that gives me the desired result:

select *, SUM(Cantidad) from (select CatArticulos.ArticuloId, ArticuloNombre, ArticuloCodigo, ArticuloUnidad, ArticuloMin, ArticuloMax, ArticulosDisponibles, Cantidad, ArticuloDesc from CatArticulos left join ContenidosDeModelos on CatArticulos.ArticuloId=ContenidosDeModelos.ArticuloId where ModeloID = {$ModeloRec{'ModeloID'}} and ArticuloDeshabilitado = 'N' and ( ArticuloPara = 'Ordenes' or ArticuloPara = 'Todos' ) union all select ArticuloId, ArticuloNombre, ArticuloCodigo, ArticuloUnidad, ArticuloMin, ArticuloMax, ArticulosDisponibles, 0.0 as Cantidad, ArticuloDesc from CatArticulos) as x group by ArticuloId order by ArticuloCodigo

However I feel that there must be a more elegant straight forward way of writing it...

Any suggestions???

Richard

 
11 years, 5 months ago Daniel Bartholomew

I've posted your question to the Maria-Discuss mailing list. Maybe someone there will have a suggestion.

 
11 years, 5 months ago Sergei Golubchik
Re: What Join [Answer]
 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.