我想看看是否有人可以帮我处理更新查询。
我需要抓住latitude
&来自两个longitude
中的同一用户的accounts
。因此,我试图在一个帐户的用户表中update
lat / long,基于另一个帐户中的同一用户。我通过电话号码和姓氏匹配用户。我尝试了subquery
,但遇到了困难。
我在考虑以下内容:
update users
set lat = getlat, long = getlong
inner join (select lat as getlat, long as get long from users where account_id = '1')
on phone = phone and last name = lastname
where account_id = '2' and lat IS NULL and long IS NULL
我正朝着正确的方向前进吗?
提前感谢您的任何帮助!!!!
答案 0 :(得分:0)
Alias
sub-query
个名称
同时选择phone
中的lastname
和sub-query
列,将其加入Users
表
update U
set U.lat = A.getlat, U.long = A.getlong
From users U
inner join
(
select lat as getlat, long as getlong,phone ,lastname
from users
where account_id = '1'
) A
on U.phone = A.phone and U.lastname = A.lastname
where account_id = '2'
and lat IS NULL
and long IS NULL