0
select product.id,product.name,product.itemcode,sum(product.amount)as total_amount
from product where product.account in
select G.account from  report_results G 
where     G.status='Y')
group by product.id,product.name,product.itemcode

Consider the above as QUERY1

Now in order to perform an operation i modified the QUERY1 as below(i am using a new table called proc_temp

 (select product.id,product.name,product.itemcode,sum(product.amount)as total_amount
   from product where product.account in
   (select G.account from  report_results G 
   where     G.status='Y'))as Input,proc_temp
   where Input.id=proc_temp.id

The above query is not correctly formed.I want to join query1 with a new table proc_temp and compare both of its id column.Please help me in correcting this syntactically.

1
  • Please provide sample data and desired output. Commented Sep 4, 2012 at 15:03

2 Answers 2

1

You need to add a SELECT clause. I can't vouch for this query since I don't know what you want to do, but something like:

select i.*
from (
    select product.id, product.name, product.itemcode, sum(product.amount) as total_amount
    from product
    where product.account in (
            select G.account
            from report_results G
            where G.status = 'Y'
            )
) i
inner join proc_temp t on i.id = t.id
Sign up to request clarification or add additional context in comments.

1 Comment

@paul i.id comes from the derived table immmediately after the first from keyword
1

I would get rid of the subquery, and use an inner join. Besides that, the following query assumes that Input.id is G.account

select p.id,p.name,p.itemcode,sum(p.amount)as total_amount
from product p
inner join report_results g on (p.account = g.account)
inner join proc_temp pt on (g.account = pt.id)
where g.status='Y'
group by product.id,product.name,product.itemcode

1 Comment

@Carlos.Thanks for the response

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.