Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 27th, 2003, 08:48 AM
tandelaf tandelaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 67 tandelaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 50 m 57 sec
Reputation Power: 5
Not getting the desired amount of rows. Help!

Hi all!
I have a database wich has a table named 'productos', filled with 31 of them. I run a query (with JOINS) and it only returns me 20 rows. I want the 31 productos even if the SUMīs are zero or nonexistent. I guess I am doing something wrong with the joins or have a theory problem. Any help is appreciated.

The query:

SELECT productos.producto_id, SUM( ingreso_mes_1 + ingreso_mes_2 + ingreso_mes_3 + ingreso_mes_4 + ingreso_mes_5 + ingreso_mes_6 + ingreso_mes_7 + ingreso_mes_8 + ingreso_mes_9 + ingreso_mes_10 + ingreso_mes_11 + ingreso_mes_12) AS ingreso, SUM(costo_mes_1 + costo_mes_2 + costo_mes_3 + costo_mes_4 + costo_mes_5 + costo_mes_6 + costo_mes_7 + costo_mes_8 + costo_mes_9 + costo_mes_10 + costo_mes_11 + costo_mes_12) AS costo
FROM productos
LEFT JOIN ventas
USING ( producto_id)
LEFT JOIN clientes
USING (cliente_id)
WHERE clientes.canal_id = 1
AND ventas.destino_id = 1
GROUP BY productos.producto_id

Thanks!

*If you need additional info, just ask.
__________________
..:: Ignorance is *really* bliss (trust me)::..

Reply With Quote
  #2  
Old November 2nd, 2003, 04:14 PM
rhpoole rhpoole is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Rogers, AR
Posts: 5 rhpoole User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am a little vague on what you are trying to do, but I think that you do have a problem with your joins. You may need to segregate them, something like this:

SELECT productos.producto_id, SUM( ingreso_mes_1 + ingreso_mes_2 + ingreso_mes_3 + ingreso_mes_4 + ingreso_mes_5 + ingreso_mes_6 + ingreso_mes_7 + ingreso_mes_8 + ingreso_mes_9 + ingreso_mes_10 + ingreso_mes_11 + ingreso_mes_12) AS ingreso, SUM(costo_mes_1 + costo_mes_2 + costo_mes_3 + costo_mes_4 + costo_mes_5 + costo_mes_6 + costo_mes_7 + costo_mes_8 + costo_mes_9 + costo_mes_10 + costo_mes_11 + costo_mes_12) AS costo
FROM (productos LEFT JOIN ventas USING (producto_id))
LEFT JOIN clientes
USING (cliente_id)
WHERE clientes.canal_id = 1
AND ventas.destino_id = 1
GROUP BY productos.producto_id

HTH,
Russ

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Not getting the desired amount of rows. Help!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway