dbTalk Databases Forums  

Help needed with subquery

comp.databases.postgresql comp.databases.postgresql


Discuss Help needed with subquery in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dave
 
Posts: n/a

Default Help needed with subquery - 12-16-2008 , 12:38 PM






CREATE TABLE "o"."tb_main" (
"cust_id" VARCHAR,
"order_no" VARCHAR
) WITH OIDS;

CREATE TABLE "o"."tb_detail" (
"order_no" VARCHAR,
"item_name" INTEGER,
"price" INTEGER
) WITH OIDS;

I'm trying to query order_no rows for a specific cust_id from the main
table, but on the same row, I would also like to show all item_name COUNT
for each order, where price > 0.
order_no | item_name
----------------------
1 | 15
2 | 7


Here is what I tried:
SELECT * FROM "o"."tb_main"
LEFT JOIN (SELECT COUNT(item_name) FROM "o"."tb_detail" WHERE price > 0 )
AS pcount
ON tb_main.order_no = tb_detaill.order_no
WHERE cust_id=1;

Obviously above doesn't work but cannot figure out the syntax.
Can anyone help?

Thanks



Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.