programing

MySQL Update 내부 가입 테이블 쿼리

kingscode 2023. 1. 22. 22:37
반응형

MySQL Update 내부 가입 테이블 쿼리

뭐가 문제인지 전혀 모르겠어요.MySQL 5.0을 사용하여 다음 MySQL 업데이트 쿼리를 실행하려고 하면 컴파일 오류가 발생합니다.

UPDATE  b
SET b.mapx = g.latitude,
    b.mapy = g.longitude
FROM business AS b
INNER JOIN business_geocode g ON b.business_id = g.business_id
WHERE (b.mapx = '' OR b.mapx = 0) AND
      g.latitude > 0

모든 필드 이름이 올바릅니다.무슨 생각 있어?

이것을 시험해 보세요.

UPDATE business AS b
INNER JOIN business_geocode AS g ON b.business_id = g.business_id
SET b.mapx = g.latitude,
  b.mapy = g.longitude
WHERE  (b.mapx = '' or b.mapx = 0) and
  g.latitude > 0

업데이트:

쿼리에서 구문 오류가 발생했다고 하셨기 때문에 테스트할 수 있는 테이블을 몇 개 만들고 쿼리에 구문 오류가 없음을 확인했습니다.

mysql> create table business (business_id int unsigned primary key auto_increment, mapx varchar(255), mapy varchar(255)) engine=innodb;
Query OK, 0 rows affected (0.01 sec)

mysql> create table business_geocode (business_geocode_id int unsigned primary key auto_increment, business_id int unsigned not null, latitude varchar(255) not null, longitude varchar(255) not null, foreign key (business_id) references business(business_id)) engine=innodb;
Query OK, 0 rows affected (0.01 sec)

mysql> UPDATE business AS b
    -> INNER JOIN business_geocode AS g ON b.business_id = g.business_id
    -> SET b.mapx = g.latitude,
    ->   b.mapy = g.longitude
    -> WHERE  (b.mapx = '' or b.mapx = 0) and
    ->   g.latitude > 0;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0

봤지? 구문 오류는 없어MySQL 5.5.8에 대해 테스트했습니다.

SET절은 테이블 지정 뒤에 와야 합니다.

UPDATE business AS b
INNER JOIN business_geocode g ON b.business_id = g.business_id
SET b.mapx = g.latitude,
  b.mapy = g.longitude
WHERE  (b.mapx = '' or b.mapx = 0) and
  g.latitude > 0

MySql WorkBench의 경우 다음을 사용하십시오.

update emp as a
inner join department b on a.department_id=b.id
set a.department_name=b.name
where a.emp_id in (10,11,12); 

언급URL : https://stackoverflow.com/questions/8057565/mysql-update-inner-join-tables-query

반응형