[英]mysql update query syntax
I'm trying to use the following query syntax from a php file: 我正在尝试从php文件中使用以下查询语法:
$sql = "UPDATE properties SET properties.ht_hs = 3.5 WHERE properties.oil_data_id = acea.oil_data_id AND (acea.ACEA_A3 = 1 OR acea.ACEA_B3 = 1 OR acea.ACEA_B4 = 1) AND properties.ht_hs < 3.5";
$result = mysql_query($sql) or die(mysql_error());
However, It's not doing what I want. 但是,它没有满足我的要求。 I have two tables in my database, and I need to change the value of some of the records for one column within one of the tables (the ht_hs column/field within the properties table).
我的数据库中有两个表,我需要更改其中一个表(属性表中的ht_hs列/字段)中某一列的某些记录的值。 However,the criteria for when to change that field is dependent upon both tables.
但是,何时更改该字段的标准取决于两个表。
Each motor oil in the database has an id, which is listed in the "oil_data_id" column of each table. 数据库中的每种机油都有一个ID,该ID在每个表的“ oil_data_id”列中列出。
I'm trying to find oils that meet the ACEA A3 or B3 or B4 spec (ie, they have a "1" in that column of the acea table) which also have a value of less than 3.5 in the ht_hs column of the properties table. 我正在尝试找到符合ACEA A3或B3或B4规格的油(即,acea表的该列中的值为“ 1”),并且该属性的ht_hs列中的值也小于3.5表。
If they do, I want to update the value to 3.5. 如果他们这样做,我想将该值更新为3.5。
How can I restructure my query so that it works? 如何重组查询,使其有效?
I think you're looking for something like this: 我认为您正在寻找这样的东西:
UPDATE properties
SET properties.ht_hs = 3.5
WHERE properties.oil_data_id in
(select acea.oil_data_id
from acea
where (acea.ACEA_A3 = 1 OR acea.ACEA_B3 = 1 OR acea.ACEA_B4 = 1))
AND properties.ht_hs < 3.5;
You would need to include table acea
in the JOIN like :- 您需要在JOIN中包括表
acea
:
UPDATE properties, acea
SET ...;
See the documentation 请参阅说明文件
UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.