简体   繁体   English

在MySQL中在一个查询中更新多个表

[英]Update multiple tables in one query, in MySQL

I want update my tables from csv. 我想从csv更新表格。 Now data from csv are imported to table "temp_update_stany", but i cant update tables. 现在,来自csv的数据被导入到表“ temp_update_stany”中,但是我无法更新表。 Query with no errors, but nothing is updated. 查询没有错误,但是没有任何更新。

Table from CSV is: CSV中的表格为:

produkt|quantity|price|active|czas

Query: 查询:

UPDATE lp2_product tabela 
        INNER JOIN lp2_stock_available stany ON (tabela.id_product = stany.id_product)
        INNER JOIN lp2_product_lang lang ON (tabela.id_product = lang.id_product)
        INNER JOIN temp_update_stany csv ON (tabela.id_product = csv.produkt)
    SET
        tabela.active = csv.active,
        tabela.price = csv.price,
        lang.available_now = csv.czas,
        stany.quantity = csv.quantity
    WHERE
        csv.produkt = tabela.id_product 
        OR csv.produkt = lang.id_product 
        OR csv.produkt = stany.id_product

and output from query: 并从查询输出:

Modified records: 0 (Perform queries took 0.0322 seconds (s)).

but for example "lp2_product" /row 'active' have value 0 for all products and temp_update_stany have value 1 for all. 但例如,“ lp2_product” /行“活动”的所有产品的值为0,而temp_update_stany所有产品的值为1。

Yes, this is prestashop and simple script for update quantity and prices. 是的,这是用于更新数量和价格的prestashop和简单脚本。

As per comments above, the UPDATE reports zero rows affected if there is no net change. 根据上面的评论,如果没有净变化, UPDATE报告受影响的零行。 So if the tables are already updated with the desired values, the UPDATE is a no-op and no rows are "affected." 因此,如果表已使用所需的值进行了更新,则UPDATE是无操作的,并且不会“影响”行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM