create temporary table tt (primary key (username)) select distinct username, user_id from users,nasdaq_location where id=user_id and location = "";
create temporary table ttt select max(msg_id) as msg_id,username,user_id from raw_ipn_field, tt where name='item_number' and value=username group by username;
create temporary table tttt (primary key (username)) select username,user_id,concat(A.value, " ", B.value, " ", C.value) as location from ttt, raw_ipn_field as A, raw_ipn_field as B, raw_ipn_field as C where A.msg_id = ttt.msg_id and B.msg_id = ttt.msg_id and C.msg_id = ttt.msg_id and A.name="address_city" and B.name="address_state" and C.name="address_country";
update nasdaq_location,tttt set nasdaq_location.location=tttt.location where nasdaq_location.user_id = tttt.user_id and nasdaq_location.location="";
update users,tttt set nasdaq_location=tttt.location where id = tttt.user_id and nasdaq_location="";

