Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何使用Where语句从Select更新_Sql_Postgresql_Sql Update - Fatal编程技术网

Sql 如何使用Where语句从Select更新

Sql 如何使用Where语句从Select更新,sql,postgresql,sql-update,Sql,Postgresql,Sql Update,我在试图找到这个问题的答案时遇到了一个小问题。我需要使用带有Where语句的Select,使用Update将新信息放入某些行中 在我的主表中有列 Equipment_ID Type Unit_Name Address Latitude Longitude 在aux表中,我为每个ID更新了纬度和经度 Equipment_ID Type Latitude Longitude 因此,我需要将每个ID的新Lat和Lon放在主表中的旧Lat和Lon之上。我认为这样做会奏效,但在这个例子中

我在试图找到这个问题的答案时遇到了一个小问题。我需要使用带有Where语句的Select,使用Update将新信息放入某些行中

在我的主表中有列

Equipment_ID  Type  Unit_Name  Address  Latitude  Longitude
在aux表中,我为每个ID更新了纬度和经度

Equipment_ID Type  Latitude Longitude 
因此,我需要将每个ID的新Lat和Lon放在主表中的旧Lat和Lon之上。我认为这样做会奏效,但在这个例子中,我在另一个问题中发现,他只更新了一个字段,这让我很困惑

 UPDATE  a
 SET     a.marks = b.marks
 FROM    tempDataView a
   INNER JOIN tempData b
     ON a.Name = b.Name
如何更新纬度和经度,但作为where语句,仅在

WHERE main.Equipment_ID = aux.Equipment_ID
AND   main.Type         = aux.Type

提前感谢您提供的提示。

您不能在更新语句中使用
JOIN
,您需要在
where
子句中执行“JOIN”

另外:不要重复
FROM
子句中的目标表:

UPDATE  main
   SET latitude = aux.latitude, 
       longitude = aux.longitude
FROM aux
WHERE main.Equipment_ID = aux.Equipment_ID
AND   main.Type         = aux.Type

不能在update语句中使用
JOIN
,需要在
where
子句中执行“JOIN”

另外:不要重复
FROM
子句中的目标表:

UPDATE  main
   SET latitude = aux.latitude, 
       longitude = aux.longitude
FROM aux
WHERE main.Equipment_ID = aux.Equipment_ID
AND   main.Type         = aux.Type
好的,从技术上讲,您可以在
更新中使用
JOIN
,只是不针对正在更新的表引用。好的,从技术上讲,您可以在
更新中使用
JOIN
,只是不针对正在更新的表引用。