Hello,
I didn't understood your question well,
but i think this might help
----Create Table Script
Create Table Collection
(
id int Primary key ,
clientid Varchar(6),
company Varchar(30),
product Varchar(30),
total money
)
Insert Into Collection Values ('1','2001','Company1','Product1','50000')
Insert Into Collection Values ('2','2002','Company2','Product2','60000')
Insert Into Collection Values ('3','2003','Company3','Product3','70000')
Create Table PaymentData
(
wid int Primary key ,
wcid int FOREIGN KEY REFERENCES Collection(id),
clientid Varchar(6),
product Varchar(30),
rcvamt money,
restamt money
)
Insert Into PaymentData Values('1','1','2001','Product1','500','49500')
Insert Into PaymentData Values('2','1','2001','Product1','800','48700')
Insert Into PaymentData Values('3','2','2002','Product2','1500','58500')
Create Table Payment
(
id int Primary key ,
wid int FOREIGN KEY REFERENCES PaymentData(wid),
clientid Varchar(6),
product Varchar(30),
rcvamt money ,
restamt money,
)
Insert Into Payment Values('1','1','2001','Product1','1300','48700')
Insert Into Payment Values('2','3','2002','Product2','1500','58500')
---After Creating tables your solution should be
Select A.clientid,A.company,A.product,A.total,B.rcvamt,B.restamt From Collection A
Left Join Payment B
On A.id = B.id