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 |
|
eddie
Starting Member
45 Posts |
Posted - 2002-04-22 : 16:05:56
|
| It must be Monday because I am having a brain cramp. I have two tables,t1 contains an cust_id and a date column.t2 contains an id and a date column.T1 has only one row per customer, t2 contains several rows for each customer. I need to update t1.date with the minimum date per customer from t2. T1.cust_id=t2.idSo in T2 if I have these rowsid date12541 02/01/200012541 01/01/199912541 03/02/1997I need to update with 12541 row in t1 setting the date to 03/02/1997How can I do this?Thanks,Eddie |
|
|
skond
Yak Posting Veteran
55 Posts |
Posted - 2002-04-22 : 17:41:15
|
| update t1set t1.data = A.datefromt1,(select t2.id,min(date) as min_datafrom t2) Awhere t1.cust_id = t2.id |
 |
|
|
skond
Yak Posting Veteran
55 Posts |
Posted - 2002-04-22 : 17:42:17
|
| -- correct the last post , add group byupdate t1 set t1.data = A.date from t1, ( select t2.id,min(date) as min_data from t2 group by t2.id) A where t1.cust_id = t2.id |
 |
|
|
skond
Yak Posting Veteran
55 Posts |
Posted - 2002-04-22 : 17:43:21
|
| --one more correction, use A.min_dateupdate t1 set t1.data = A.min_date from t1, ( select t2.id,min(date) as min_data from t2 ) A where t1.cust_id = t2.id |
 |
|
|
skond
Yak Posting Veteran
55 Posts |
Posted - 2002-04-22 : 17:44:27
|
| --one more correction, join using A.idupdate t1 set t1.data = A.min_date from t1, ( select t2.id,min(date) as min_data from t2 ) A where t1.cust_id = A.id |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2002-04-22 : 18:21:53
|
| Skond,There is a "edit" facility on SQLTeam....DavidMTomorrow is the same day as Today was the day before. |
 |
|
|
eddie
Starting Member
45 Posts |
Posted - 2002-04-23 : 08:43:42
|
| Thanks, that appears to work!Thanks,Eddie |
 |
|
|
skond
Yak Posting Veteran
55 Posts |
Posted - 2002-04-23 : 09:13:14
|
quote: --one more correction, join using A.idupdate t1 set t1.data = A.min_date from t1, ( select t2.id,min(date) as min_data from t2 group by t2.id) A where t1.cust_id = A.id
|
 |
|
|
|
|
|
|
|