I have following query:
UPDATE `order_tab`
LEFT JOIN `currency_tab`
ON (`order_tab`.`order_actual_loading_date` = `currency_tab`.`currency_date`)
SET `order_tab`.`order_cost_converted` = (`order_tab`.`order_cost_pricelist` * `currency_tab`.`currency_value`);
After running I have error:
You have an error in your SQL syntax near 'LEFT JOIN
currency_tab
ON (order_tab
.order_actual_loading_date
= `order_c' at line 2
MySQL version:
+---------------+-------------+
| Variable_name | Value |
+---------------+-------------+
| version | 3.23.52-log |
+---------------+-------------+
order_tab
+---------------------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------------------+------------------+------+-----+---------+----------------+
| order_id | int(10) unsigned | | PRI | NULL | auto_increment |
| user_id | int(10) unsigned | | | 0 | |
| order_loading_address | blob | YES | | NULL | |
| order_loading_city | varchar(50) | YES | | NULL | |
| order_unloading_address | blob | YES | | NULL | |
| order_unloading_city | varchar(50) | YES | | NULL | |
| order_desc | blob | YES | | NULL | |
| order_collect_date_start | date | YES | | NULL | |
| order_collect_date_end | date | YES | | NULL | |
| order_delivery_date | date | YES | | NULL | |
| order_cost_pricelist | float(11,2) | YES | | NULL | |
| order_currency_pricelist | varchar(6) | YES | | NULL | |
| order_cost_forwarder | float(11,2) | YES | | NULL | |
| order_currency_forwarder | varchar(6) | YES | | NULL | |
| order_cost_converted | float(11,2) | YES | | NULL | |
| order_currency_converted | varchar(6) | YES | | NULL | |
| order_distance | float(11,2) | YES | | NULL | |
| order_activation_date | datetime | YES | | NULL | |
| order_state | int(2) unsigned | | | 0 | |
| order_notes | blob | YES | | NULL | |
| order_date | datetime | YES | | NULL | |
| order_payer | varchar(50) | YES | | NULL | |
| order_receiver | varchar(50) | YES | | NULL | |
| order_forwarder | int(10) unsigned | YES | | NULL | |
| order_forwarder_car_no | varchar(10) | YES | | NULL | |
| order_forwarder_contact_address | blob | YES | | NULL | |
| order_forwarder_trailer_no | varchar(20) | YES | | NULL | |
| order_reservation_date | datetime | YES | | NULL | |
| order_assortment | varchar(11) | YES | | NULL | |
| order_weight | float(6,3) | YES | | NULL | |
| order_group | int(2) unsigned | YES | | NULL | |
| order_type | int(2) unsigned | YES | | NULL | |
| order_invoice_no | varchar(10) | YES | | NULL | |
| order_closing_date | datetime | YES | | NULL | |
| order_actual_loading_date | date | YES | | NULL | |
| order_actual_unloading_date | date | YES | | NULL | |
| order_company_offerer | varchar(11) | | | | |
| objversion | timestamp(14) | YES | | NULL | |
+---------------------------------+------------------+------+-----+---------+----------------+
currency_tab
+----------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+------------+------+-----+---------+-------+
| currency_date | date | YES | | NULL | |
| currency_value | float(6,4) | YES | | NULL | |
+----------------+------------+------+-----+---------+-------+
How can I avoid this error?
I think this code should work:
UPDATE `order_tab`, `currency_tab`
SET `order_tab`.`order_cost_converted` = (`order_tab`.`order_cost_pricelist` * `currency_tab`.`currency_value`)
WHERE (`order_tab`.`order_actual_loading_date` = `currency_tab`.`currency_date`)
OR [recommended]
UPDATE `order_tab`
SET `order_tab`.`order_cost_converted` = (`order_tab`.`order_cost_pricelist` * (SELECT `currency_tab`.`currency_value` FROM `currency_tab`
WHERE `order_tab`.`order_actual_loading_date` = `currency_tab`.`currency_date`))
NOTE :
UsingLEFT JOIN
makescurrency_tab
.currency_value
sometimes NULL
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.