Click here to Skip to main content
16,005,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Table Studetail
SQL
Stuid int,
name varchar(50),
college varchar(50)


Table Stuadd
SQL
id int,
address varhcar(50)
Table amount
name varchar(50),
amount float


i have to generate query according to id or name to find
Studetail.Stuid, Studetail.name, Studetail.college, Stuadd.address, sum(amount.amount)
Posted
Updated 5-Jun-12 20:37pm
v2

I think it is better to use Stuid to establish relation between Studetail and Amount table like

Amount Table
id int,
amount float

in which case the following query can be used to get the result sought in the question

SQL
SELECT Studetail.Stuid, Studetail.name, Studetail.college, Stuadd.address,
    (SELECT SUM(Amount) FROM Amount WHERE Studetail.Stuid= amount.id) AS TotalAmount
FROM Studetail INNER JOIN Stuadd ON Studetail.Stuid = Stuadd.id
 
Share this answer
 
v2
Comments
roxyraj 6-Jun-12 3:10am    
Thanks...
VJ Reddy 6-Jun-12 4:35am    
You're welcome and thank you for accepting the solution :)
Maciej Los 6-Jun-12 18:01pm    
Good answer, my 5!
VJ Reddy 6-Jun-12 19:38pm    
Thank you, losmac :)
thatraja 6-Jun-12 21:24pm    
5!
Hi,
SQL
select Studetail.Stuid, Studetail.name, Studetail.college,sum(amount.amount) from Studetail join amount on Studetail.name=amount.name


u haven't given any id for join i have used join with the name
 
Share this answer
 
v2
Comments
AmitGajjar 6-Jun-12 5:20am    
join with the name is not correct way of joining. disagree with this solution.
Maciej Los 6-Jun-12 18:03pm    
Agree with you.
Maciej Los 6-Jun-12 18:05pm    
I'll give a chance to correct your solution.
hi,
I do agree with the solution. default we use id but there is no chance of join with id
 
Share this answer
 

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