If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > how to join two subquery?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-15-11, 01:37
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
how to join two subquery?

I am using Sybase ASE 12.5
I have two table as follow

TableA
PID, Amount1
1, 10
1, 20
2, 10
2, 10
3, 30

TableB
PID, Amount2
1, 20
1, 50
2, 30
2, 20

SELECT one.pid
, one.Amount1OfSum
, two.Amount2OfSum
FROM ( SELECT pid
, SUM(Amount1) AS Amount1OfSum
FROM TableA
GROUP
BY pid ) AS one,
( SELECT pid
, SUM(Amount2) AS Amount2OfSum
FROM TableB
GROUP
BY pid ) AS two
where two.pid *= one.pid

What I want the output is
PID, Amount1, Amount2
1, 30, 70
2, 20, 50
3, 30,

Incorrect syntax near the keyword 'select'.
Incorrect syntax near ')'.

Thank.
Reply With Quote
  #2 (permalink)  
Old 06-15-11, 05:31
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
The "*=" is not SQL syntax. You want to have a LEFT OUTER JOIN or FULL OUTER JOIN with a join predicate of "one.pid = two.pid".
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 06-15-11, 21:54
manhjk manhjk is offline
Registered User
 
Join Date: May 2011
Posts: 13
Hi stolze,

Thank very much for your reply.

I finally got the answer.
Sybase ASE 12.5.0.3 version is not support "derivedtable", so it is not the syntex problem.

I have to do it by using temp table or sp

Thank
Reply With Quote
  #4 (permalink)  
Old 06-16-11, 11:33
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Well, aside from the "*=" stuff, your syntax is fine and acceptable standard SQL. It seems that your product deviates from the standard, however.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On