I think you want a subquery. Something like UPDATE t1 SET last_login_time = (SELECT MAX(logintime) FROM t2 WHERE t1.userid = t2.userid);
would be a good start. Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 > -----Original Message----- > From: Ravi Kumar. [mailto:[EMAIL PROTECTED] > Sent: Wednesday, April 11, 2007 7:23 AM > To: mysql@lists.mysql.com > Subject: Join & update help > > Dear All, > > I have two tables T1 and T2. > > T1 has these columns: userid, password (userid is primary key) > > T2 has these columns: sessionid, userid, logintime, logofftime > (sessionid is primary key) > > I wish to add one column in T1 called last_login_time. > > I want to populate this new column with max(logintime) from > T2 for each > user. How do I do this? I tried variants of this: > update T1, T2 set last_login_time = max(logintime) where T1.userid = > T2.userid. > > Thanks > > Ravi. > > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: > http://lists.mysql.com/[EMAIL PROTECTED] > > -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]