从不同表中插入新记录
我正在尝试通过加入将新记录添加到表_1中的表_1,但我没有得到正确的结果。
我正在尝试将纬度和经度从表_2复制到table_1。
我的表_1带有列地址,纬度,经度
纬度&经度是空白的。
Table_2具有列地址,纬度,经度,名称,地址等。
在两个表中,地址都有一个城市名称。
insert into table_1 (latitude, longitude)
select table_2.latitude, table_2.longitude from table_2 JOIN table_1 ON table_1.address = table_2.address;
Getting this output: table_1
address latitude longitude
city_1 NULL NULL
city_2 NULL NULL
city_3 NULL NULL
NULL 123.12 123.12
NULL 123.12 123.12
NULL 123.12 123.12
我期待这样的事情:
address latitude longitude
city_1 123.12 123.12
city_2 123.12 123.12
city_3 123.12 123.12
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的情况下,您应该使用
update
语句而不是insert
,因为第一个表中的条目已经存在,您只需要在 dbfiddle
In your case, you should use the
update
statement instead ofinsert
, since the entries in the first table one already exist, and you just need to update themDemo in dbfiddle