Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
great_mamun
Starting Member
14 Posts |
Posted - 2008-07-08 : 05:04:50
|
| Dear All,Schema:table1(id,prod_name,price) // id is primary keytable2(id,quantity,date) // id is references from table1select t1.id, t1.prod_name, t1.price, sum(t2.quantity), min(t2.date) from table1 t1, table2 t2where t1.id=t2.idgroup by t1.idthe above query didn't work.I want all values from table1 and sum of quantity for same id and the minimum date among the same ids.plz can anyone help me.Best Regards,Abdullah Al Mamun |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-08 : 05:07:03
|
[code]SELECT t1.id, t1.prod_name, t1.price, t2.quantity, t2.dateFROM table1 t1 INNER JOIN ( SELECT id, quantity = SUM(quantity), date = MIN(date) FROM tabel2 GROUP BY id ) t2 ON t1.id = t2.id[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
great_mamun
Starting Member
14 Posts |
Posted - 2008-07-08 : 05:23:47
|
| ohh that is so cool.Thank you very much for your great help.Best Regards,Abdullah Al Mamun |
 |
|
|
|
|
|
|
|