Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my DB there are only 4 or5 records in my tables but the query below is showing 12 or 13 records it's showing 1 record 3 times and so on

SQL
select A.Date,OwnerName,Rate,Weight,PreviousAmount from Company F inner join TrashSaleOrders C on F.Companyid=C.Companyid  inner join Accounts A on C.Companyid=A.Companyid


I want to display Name (OwnerName) of person who ordered and Orderdetails (Rate,Weight) and his previous amount (PreviousAmount) if any. Table Company contains (Companyid,OwnerName) Table TrashSaleOrders contains (Companyid,Date,Weight,Rate) Table Accounts contains (Accountid,Companyid,Date,PreviousAmount,Payment,AmountLeft)
Posted
Updated 28-May-13 18:21pm
v2
Comments
Rockstar_ 28-May-13 23:34pm    
What output u need to display?
Jameel VM 28-May-13 23:43pm    
where is the question here.Please complete the question
_Amy 28-May-13 23:59pm    
Where is the alias for OwnerName, Rate, Weight, PreviousAmount?
Zain ul abdeen 29-May-13 0:18am    
I want to display Name (OwnerName) of person who ordered and Orderdetails (Rate,Weight) and his previous amount (PreviousAmount) if any.

Table Company contains (Companyid,OwnerName)
Table TrashSaleOrders contains (Companyid,Date,Weight,Rate)
Table Accounts contains (Accountid,Companyid,Date,PreviousAmount,Payment,AmountLeft)

Hope its clear now

give group by clause and see it will resolve
 
Share this answer
 
Comments
Zain ul abdeen 29-May-13 0:23am    
Its not that.It's Showing a single record at multiple times which existed in DB only once
joins should be proper, try this...
SQL
select A.Date,OwnerName,Sum(Rate),Sum(Weight),sm(PreviousAmount)
from Company F 
inner join TrashSaleOrders C on F.Companyid=C.Companyid  
inner join Accounts A on C.Companyid=A.Companyid and A.Date = C.Date
Group by A.Date, OwnerName

Happy Coding!
:)
 
Share this answer
 
Comments
Zain ul abdeen 29-May-13 1:50am    
I did'nt want to group it but without group by it is also working well. I was not matching the Date :)
Aarti Meswania 29-May-13 1:52am    
good happy to read your comment, solution worked for you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900