This are my tables:

tblData

numIndex | num | cost

tblPrize

numIndex | num | Prize

and the result I want is :

tblData.num=tblPrize.num
then
sum the cost in tblData

example of the table view i want:

tblData.Num | SUM(tblData.cost) | tblPrize.prize

I'm assuming that you're looking for the SQL expression to accomplish this.
Here it is:
SELECT tblData.num,SUM(tblData.cost) AS Total,tblPrize.prize FROM tblData, tblPrize WHERE tblData.num = tblPrize.num GROUP BY tblData.num

Oxiegen showed how to write an sql query statement. Is that what you are looking for?
Iam asking because you said "tables", they might be dataTables, then we need a different approach, best to use Linq and Lambda Expression (in case if you got all the data from database to dataTable, and query must be done over datatable).

Which is even better if you wanna use data on many places, so you dont need to access to database each time.
Let us know.

SELECT tblData.num,SUM(tblData.cost) AS Total,tblPrize.prize FROM tblData, tblPrize WHERE tblData.num = tblPrize.num GROUP BY tblData.num

this sql is not working.
The error is "You tried to execute a quesry that does not include the specified expression 'prize' as part of an aggregate function."
I remove the tblPrize.prize and its work
What is the problme??

SELECT tblData.num,SUM(tblData.cost) AS Total,tblPrize.prize FROM tblData, tblPrize WHERE tblData.num = tblPrize.num GROUP BY tblData.num

this sql is not working.
The error is "You tried to execute a quesry that does not include the specified expression 'prize' as part of an aggregate function."
I remove the tblPrize.prize and its work
What is the problme??

SELECT tblData.num,SUM(tblData.cost) AS Total,tblPrize.prize FROM tblData, tblPrize WHERE tblData.num = tblPrize.num GROUP BY tblData.num

this sql is not working.
The error is "You tried to execute a quesry that does not include the specified expression 'prize' as part of an aggregate function."
I remove the tblPrize.prize and its work
What is the problme??

Ooops.
Try adding tblPrize.prize to the GROUP BY clause (separated by a comma).

this code shud be written

SELECT td.num,SUM(td.cost) AS Total,tp.prize FROM tblData td, tblPrize tp WHERE td.num = tp.num GROUP BY td.num, tp.Prize
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.