Home » SQL & PL/SQL » SQL & PL/SQL » GROUP BY with 3 tables (Oracle 11g)
GROUP BY with 3 tables [message #649728] Mon, 04 April 2016 21:08 Go to next message
myoratom
Messages: 1
Registered: April 2016
Junior Member
Hi,
Below are my 3 tables.

1) ORDER_HEADER ( OH_NUM, customer_ID) - OH number is unique key
2) ORDER_LINE ( OL_ID, OH_NUM , PROD_ID ) - OL Line ID is unique key
3) PRODUCT__DETAIL table ( PROD_ID , PROD_GROUP)

Now I want to write a SQL to find the count of Orders group by PROD Group

select PROD_GROUP, count(1)
from ORDER_HEADER OH, ORDER_LINE OL, PRODUCT_DETAIL PD
WHERE OH.OH_NUM =OL.OH_NUM
AND OL.PROD_ID = PD.PROD_ID


The above query is giving incorrect count. Can you please help?
Re: GROUP BY with 3 tables [message #649730 is a reply to message #649728] Mon, 04 April 2016 22:03 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum

Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read

How are we to know what the correct count should be?

>COUNT(1)
why above?

Re: GROUP BY with 3 tables [message #649731 is a reply to message #649728] Tue, 05 April 2016 00:30 Go to previous message
Michel Cadot
Messages: 68665
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
The above query is giving incorrect count.


It does not return any count as it is not a valid syntax.

Note: table ORDER_HEADER is useless to answer the question, you only need the 2 other ones 'assuming the question is the number of orders for each PROD_GROUP).

Previous Topic: find Characters which are not present in keyboard
Next Topic: Member functios in Collection
Goto Forum:
  


Current Time: Sun Jun 30 15:59:01 CDT 2024