join - MySQL query for summing values in another table -


i have got couple of tables parent child relationship. want apply sum function 1 column of child table , return data of parent table example.

parent_table id, date, title  child_table id, another_id, column_to_sum //(id foreign key pointing parent_table)  sample data in parent_table 1, 22-11-2010 00:00:00 , 'some title' 2, 13-11-2010 00:00:00 , 'some title 2'  sample data in child_table 1, 1, 10 1, 2, 11 1, 8, 3 2, 5, 11 2, 8, 6 

output of query should return columns in parent_table additional column, is, summing values of column_to_sum in child_table each item in parent_table matched id.

how?

    select p.id,       p.date,       p.title,       sum(c.column_to_sum) total     parent_table p left join        child_table c on p.id = c.id     group p.id 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -