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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Plz some body help me...

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 key
table2(id,quantity,date) // id is references from table1

select t1.id, t1.prod_name, t1.price, sum(t2.quantity), min(t2.date) from table1 t1, table2 t2
where t1.id=t2.id
group by t1.id

the 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.date
FROM 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]

Go to Top of Page

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
Go to Top of Page
   

- Advertisement -