Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 JOINING RECORDS

Author  Topic 

lovinguy
Starting Member

12 Posts

Posted - 2009-07-03 : 12:40:41
HI!

I know my question is something do with inner join but i am new to SQL so I need help.


Table 1 -Sales_main
Columns name (DocNo,docdate,netamount)

Table 2 - Sales_detail
Columns name (Docno,docdate,amount)


Table 1 has total amount or sum of a transaction but details of the transaction is in Table 2.For example if customer purchased 4 items then total amount of 4 items is in only Table 1 but Table 2 has details of individual items with amount.

I need a query that if netamount=5 in Table1 then I should get details of the transaction from Table2.

Waiting for reply.


Thanks

Lovinguy

singularity
Posting Yak Master

153 Posts

Posted - 2009-07-03 : 13:53:06
select Docno, docdate, amount
from Sales_detail
where Docno in (select Docno from Sales_main where netamount = 5)

Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-04 : 02:47:10
try this too
SELECT Docno, docdate, amount
from Sales_detail d
where EXISTS (select * from Sales_main where netamount = 5 AND docno = d.docno)

SELECT d.docno,d.docdate,d.amount
from sales_Detail d
inner join sales_main m on m.docno= d.docno
and m.netamount = 5
Go to Top of Page
   

- Advertisement -