I have a database update which works on one server but fails on another. The working server is Windows 10 running MySQL 5.7.27 while the other is Linux running MySQL 5.7.26. On both servers there is only a single user, so there cannot be any conflicts with other processes.
I have tried copying exactly the same data from the Linux server to the Windows server to see if it as data problem, but the Windows server never fails.
After the transaction I execute two SELECTS as shown below:
-- QUERY #1
SELECT SQL_CALC_FOUND_ROWS invoice_item.*, invoice_header.party_id_bill_from, invoice_header.currency_code_tx, invoice_header.currency_code_fn, invoice_header.exchange_rate, invoice_header.invoice_date, invoice_header.tax_date, invoice_header.party_id_bill_to, invoice_header.invoice_status_type_id, invoice_header.order_type, invoice_header.order_id, price_component.price_type, product.product_name, product.inventory_type, product.product_subtype, product.uom_id, product.is_revision_controlled, unit_of_measure.uom_desc, unit_of_measure.uom_abbrev, COALESCE(scale, 0) AS uom_scale, party_name AS party_name_bill_to, ROUND((quantity * adjusted_price) - (COALESCE(invoice_item.free_units,0) * unit_price) , 3) AS item_value, ROUND((quantity * adjusted_price_tx) - (COALESCE(invoice_item.free_units,0) * unit_price_tx) , 3) AS item_value_tx, adjusted_price - (unit_price + COALESCE(feature_price , 0) ) AS item_adjustment, adjusted_price_tx - (unit_price_tx + COALESCE(feature_price_tx, 0) ) AS item_adjustment_tx
FROM invoice_item
LEFT JOIN invoice_header ON (invoice_header.invoice_type=invoice_item.invoice_type AND invoice_header.invoice_id=invoice_item.invoice_id)
LEFT JOIN "gmx9_product".price_component ON (price_component.price_component_id=invoice_item.price_component_id)
LEFT JOIN "gmx9_product".product ON (product.product_id=invoice_item.product_id)
LEFT JOIN "gmx9_product".unit_of_measure ON (unit_of_measure.uom_id=invoice_item.uom_id)
LEFT JOIN "gmx9_party".party AS party_bill_to ON (party_bill_to.party_id=invoice_header.party_id_bill_to)
WHERE invoice_item.invoice_type= 'V'
AND invoice_item.invoice_id= 2856045177200000000000000000000000001
AND invoice_item.invoice_item_seq_no= '2'
ORDER BY invoice_item.invoice_id, invoice_item.invoice_item_seq_no asc
FOR UPDATE
-- QUERY #2
SELECT SQL_CALC_FOUND_ROWS invoice_account_item.*, invoice_account_header.journal_desc, invoice_account_header.uom_id_statistic AS uom_id_statistic_header, gl_account.account_id_formatted, gl_account.account_name, invoice_adjustment.adjustment_seq_no AS invoice_adjustment_seq_no, invoice_adjustment.adjustment_desc AS invoice_adjustment_desc, invoice_header.party_id_bill_from, invoice_header.party_id_bill_to, invoice_header.currency_code_fn, invoice_header.currency_code_tx, invoice_header.exchange_rate, invoice_header.adjusted_value_tx, invoice_header.invoice_status_type_id, invoice_item.invoice_item_desc, invoice_item_adjustment.adjustment_seq_no AS invoice_item_adjustment_seq_no, invoice_item_adjustment.adjustment_desc AS invoice_item_adjustment_desc, invoice_item_feature.prod_feature_id AS invoice_item_prod_feature_id
FROM invoice_account_item
LEFT JOIN invoice_account_header ON (invoice_account_header.invoice_type=invoice_account_item.invoice_type
AND invoice_account_header.invoice_id=invoice_account_item.invoice_id)
LEFT JOIN "gmx9_finance_gl".gl_account ON (gl_account.chart_id=invoice_account_item.chart_id
AND gl_account.account_id=invoice_account_item.account_id)
LEFT JOIN "gmx9_invoice".invoice_adjustment ON (invoice_adjustment.invoice_type=invoice_account_item.invoice_type
AND invoice_adjustment.invoice_id=invoice_account_item.invoice_id
AND invoice_adjustment.adjustment_seq_no=invoice_account_item.invoice_adjustment_seq_no)
LEFT JOIN "gmx9_invoice".invoice_header ON (invoice_header.invoice_type=invoice_account_item.invoice_type
AND invoice_header.invoice_id=invoice_account_item.invoice_id)
LEFT JOIN "gmx9_invoice".invoice_item ON (invoice_item.invoice_type=invoice_account_item.invoice_type
AND invoice_item.invoice_id=invoice_account_item.invoice_id
AND invoice_item.invoice_item_seq_no=invoice_account_item.invoice_item_seq_no)
LEFT JOIN "gmx9_invoice".invoice_item_adjustment ON (invoice_item_adjustment.invoice_type=invoice_account_item.invoice_type
AND invoice_item_adjustment.invoice_id=invoice_account_item.invoice_id
AND invoice_item_adjustment.invoice_item_seq_no=invoice_account_item.invoice_item_seq_no
AND invoice_item_adjustment.adjustment_seq_no=invoice_account_item.invoice_item_adjustment_seq_no)
LEFT JOIN "gmx9_invoice".invoice_item_feature ON (invoice_item_feature.invoice_type=invoice_account_item.invoice_type
AND invoice_item_feature.invoice_id=invoice_account_item.invoice_id
AND invoice_item_feature.invoice_item_seq_no=invoice_account_item.invoice_item_seq_no
AND invoice_item_feature.prod_feature_id=invoice_account_item.invoice_item_prod_feature_id)
WHERE invoice_account_item.invoice_type= 'V'
AND invoice_account_item.invoice_id= 2856045177200000000000000000000000001
AND invoice_account_item.invoice_item_seq_no= '2'
LOCK IN SHARE MODE
On the Windows 10 server the 2nd SELECT works, but on the Linux server it fails with "Lock wait timeout exceeded; try restarting transaction"
Related
I recently update mysql to 8.0. Since this update a syntax error is reported in this query:
UPDATE
MinMaxAvg AS tar
INNER JOIN (
SELECT
SUBSTR(YYYYDD, 1, 8) AS timestamp,
ROUND(AVG(rainfall), 1) AS rain_total_avg,
ROUND(MIN(rainfall), 1) AS rain_total_min,
ROUND(MAX(rainfall), 1) AS rain_total_max
FROM
(
(
SELECT
MAX(rain_total) - MIN(rain_total) AS rainfall,
substr(timestamp, 1, 8) AS YYYYDD
FROM
weather
WHERE
timestamp > 0
GROUP BY
substr(timestamp, 1, 8)
) AS T1
)
GROUP BY
SUBSTR(YYYYDD, 1, 8)
) AS sor ON tar.timestamp = sor.timestamp
SET
tar.rain_total_avg = sor.rain_total_avg,
tar.rain_total_min = sor.rain_total_min,
tar.rain_total_max = sor.rain_total_max
Error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') GROUP BY SUBSTR(YYYYDD,1, 8)) AS sor ON tar.timestamp = sor.timestamp SET tar.
I already checked the query with several online check tools. All reported the code as okay.
What is wrong with the query?
I already checked the query with several online check tools. All reported the code as okay.
I had to remove the parantheses around T1 block:
UPDATE
MinMaxAvg AS tar
INNER JOIN (
SELECT
SUBSTR(YYYYDD, 1, 8) AS timestamp,
ROUND(AVG(rainfall), 1) AS rain_total_avg,
ROUND(MIN(rainfall), 1) AS rain_total_min,
ROUND(MAX(rainfall), 1) AS rain_total_max
FROM
(
SELECT
MAX(rain_total) - MIN(rain_total) AS rainfall,
substr(timestamp, 1, 8) AS YYYYDD
FROM
weather
WHERE
timestamp > 0
GROUP BY
substr(timestamp, 1, 8)
) AS T1
GROUP BY
SUBSTR(YYYYDD, 1, 8)
) AS sor ON tar.timestamp = sor.timestamp
SET
tar.rain_total_avg = sor.rain_total_avg,
tar.rain_total_min = sor.rain_total_min,
tar.rain_total_max = sor.rain_total_max
I found out that the windows based sql client "HeidiSQL" might be used to find syntax errors in queries.
I'm Trying to replicate queries on DOMO from microsoft acccess. I assumed I had got the correct syntax but now I'm getting a The database reported a syntax error. Not unique table/alias: 'ga_wip_due_within_one_week'
SELECT `egl_inv`.Category, `egl_inv`.StyleClass, `egl_inv`.StyleMaster,
`egl_inv`.StyleMasterDesc, `egl_inv`.Color, `egl_inv`.ColorDesc,
`egl_inv`.Size,`egl_inv`.GscSku, `egl_inv`.UPC, `egl_inv`.RedistributionFlag,
`egl_inv`.Date_Soldout, `egl_inv`.GGS, `egl_inv`.Core, `egl_inv`.CartonQty,
If(IsNull(`ga_inv`.SumOfQty=True),0,`ga_inv`.SumOfQty) AS GA_INV,
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True),
0,`ga_wip_due_within_one_week`.SumOfQty_Size_Open) AS GA_WIP,
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True)
,0,`ga_wip_due_within_one_week`.`SumOfQty_Size_Open`.SumOfQty_Size) AS CUT,
If(IsNull(`averageweeklyfcst`=True),0,`averageweeklyfcst`) AS SS,
If(IsNull(`averageweeklyfcst`=True),0,`averageweeklyfcst`.`Demand`) AS
Demand, If(IsNull(`openorder`.OpenOrders=True),0,`openorder`.OpenOrders) AS
OpenOrders, If(IsNull(`egl_inv`.SumOfQty=True),0,`egl_inv`.SumOfQty) AS
EGL_INV,
If(IsNull(`averageweeklyfcst`.Demand=True),0,`averageweeklyfcst`.Demand)
AS AvgWklyFcst
FROM `averageweeklyfcst`
RIGHT JOIN (OpenOrders RIGHT JOIN (((((`egl_inv`
LEFT JOIN `ga_inv`ON `egl_inv`.GscSku = `ga_inv`.GscSku)
LEFT JOIN `ga_wip_due_within_one_week` ON `egl_inv`.GscSku =
`ga_wip_due_within_one_week`.GscSku) LEFT JOIN `ga_wip_due_within_one_week`
ON `egl_inv`.GscSku = `ga_wip_due_within_one_week`.GscSku)
LEFT JOIN `averageweeklyfcst` ON `
egl_inv`.GscSku = `averageweeklyfcst`.GscSku)
LEFT JOIN Demand ON `egl_inv`.GscSku = `averageweeklyfcst`.GscSku) ON
`openorder`.GscSku = `egl_inv`.GscSku) ON
`averageweeklyfcst`.GscSku = `egl_inv`.GscSku
GROUP BY EGL_INV.Category, `egl_inv`.StyleClass, `egl_inv`.StyleMaster,
`egl_inv`.StyleMasterDesc, `egl_inv`.Color, `egl_inv`.ColorDesc,
`egl_inv`.Size, `egl_inv`.GscSku, `egl_inv`.UPC,
`egl_inv`.RedistributionFlag, `egl_inv`.Date_Soldout, `egl_inv`.GGS,
`egl_inv`.Core, `egl_inv`.CartonQty,
If(IsNull(`ga_inv`.SumOfQty]=True),0,`ga_inv`.SumOfQty),
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True),
0,`ga_wip_due_within_one_week`..SumOfQty_Size_Open),
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True)
,0,`ga_wip_due_within_one_week`.SumOfQty_Size),
If(IsNull(`averageweeklyfcst`=True),0,`averageweeklyfcst`),
If(IsNull(`averageweeklyfcst`.Demand=True),0,`averageweeklyfcst`),
If(IsNull(`openorder`.OpenOrders=True),0,`openorder`.OpenOrders),
If(IsNull(`egl_inv`.`SumOfQty`=True),0,`egl_inv`.`SumOfQty`),
If(IsNull(`averageweeklyfcst`.Demand=True),0,`averageweeklyfcst`.`Demand`);
The database reported a syntax error. Not unique table/alias: 'ga_wip_due_within_one_week'
You have in the middle following line
LEFT JOIN `ga_wip_due_within_one_week` ON `egl_inv`.GscSku =
`ga_wip_due_within_one_week`.GscSku) LEFT JOIN `ga_wip_due_within_one_week`
as you see you add both without an aliais for the second ad something like as
ga_wip_due_within_one_week_1 for the second
I have moved CMS to a new server and I had an error on some pages:
Unable to execute SELECT statement [SELECT SQL_CALC_FOUND_ROWS DISTINCT shop_products.id, shop_products.user_id, shop_products.route_id, shop_products.external_id, shop_products.active, shop_products.hit, shop_products.hot, shop_products.action, shop_products.archive, shop_products.brand_id, shop_products.category_id, shop_products.related_products, shop_products.old_price, shop_products.created, shop_products.updated, shop_products.views, shop_products.added_to_cart_count, shop_products.enable_comments, shop_products.tpl, shop_products_i18n.id, shop_products_i18n.locale, shop_products_i18n.name, shop_products_i18n.short_description, shop_products_i18n.full_description, shop_products_i18n.meta_title, shop_products_i18n.meta_description, shop_products_i18n.meta_keywords, IF(sum(shop_product_variants.stock) > 0, 1, 0) AS allstock FROM shop_products INNER JOIN shop_product_categories ON (shop_products.id=shop_product_categories.product_id) INNER JOIN shop_category ON (shop_products.category_id=shop_category.id) INNER JOIN shop_products_i18n ON (shop_products.id=shop_products_i18n.id AND shop_products_i18n.locale = :p1) INNER JOIN shop_product_variants ON (shop_products.id=shop_product_variants.product_id) LEFT JOIN shop_brands ON (shop_products.brand_id=shop_brands.id) WHERE shop_product_categories.category_id=:p2 AND shop_products.active=:p3 AND shop_products.archive=:p4 AND shop_category.active=:p5 GROUP BY shop_products.id ORDER BY allstock DESC,shop_product_variants.price DESC,shop_products.id DESC LIMIT 32]
I also fulfilled this request in PhpmyAdmin and got an errors of such a type:
Unexpected character. (near ":" at position 1093)
Please tell me, why there is no such error on one server, but on another server it's displayed?
It complains about this join
INNER JOIN shop_products_i18n ON (shop_products.id=shop_products_i18n.id AND shop_products_i18n.locale = :p1)
make sure you're passing p1 as an argument or join on a specific column instead of passing an argument?
I am new to Talend open studio, I need to execute a MySql update query in a job. So I tried using tMysqlrow component and specified the query in Query field. When I run the job it shows "Lock wait timeout exceeded; try restarting transaction" error.
Here is my SQL query:
UPDATE library_export AS updater INNER JOIN
(SELECT id,(max_sequence_3 - coreTable.Level_3_sequence)+1 AS reverse_sequence_3,
(max_sequence_2 - coreTable.Level_2_sequence)+1 AS reverse_sequence_2,
(max_sequence_1 - coreTable.Level_1_sequence)+1 AS reverse_sequence_1
FROM library_export AS coreTable
LEFT JOIN
(SELECT MAX(Level_3_sequence) AS max_sequence_3,Level_2_id
FROM library_export
GROUP BY Level_2_id) AS level3 ON (coreTable.Level_2_id = level3.Level_2_id)
LEFT JOIN
(SELECT MAX(Level_2_sequence) AS max_sequence_2,Level_1_id
FROM library_export GROUP BY Level_1_id) AS level2 ON (coreTable.Level_1_id = level2.Level_1_id),
(SELECT MAX(Level_1_sequence) AS max_sequence_1
FROM library_export) AS level1) AS updataBy ON (updater.id = updataBy.id)
SET updater.Level_1_new_sequence = updataBy.reverse_sequence_1,
updater.Level_2_new_sequence = updataBy.reverse_sequence_2,
updater.Level_3_new_sequence = updataBy.reverse_sequence_3
Can anybody help me to execute the update query?
This mysql query runs just fine independently. But when I use this query to create a view then Error Code: 1064 message appears in sql yog. Please identify the reason of this error.
CREATE
VIEW `databaseName`.`viewName`
AS
((SELECT
`tblgrn`.`InitialLabNo`
, `invlabtes`.`Code` AS LabNo
, `invlabmaterial`.`Description` AS material
, `invlabtessubtable`.`SrNo`
, `invlabtessubtable`.`Result`
,COALESCE(NULL, 'Verified') AS TYPE
, `tblgrn`.`Comp_Code`
, `tblgrn`.`Unit_Code`
, `tblgrn`.`UserId`
FROM
`tblgrn`
INNER JOIN `invlabtes`
ON (`tblgrn`.`InitialLabNo` = `invlabtes`.`Code`)
INNER JOIN `invlabtessubtable`
ON (`invlabtes`.`Code` = `invlabtessubtable`.`Code`)
INNER JOIN `invlabmaterial`
ON (`invlabtessubtable`.`TestCode` = `invlabmaterial`.`Code`))
UNION
(SELECT
`tblgrn`.`InitialLabNo`
, `invlabtesscale`.`Code` AS LabNo
, `invlabmaterial`.`Description`
, `invlabscalesubtable`.`SrNo`
, `invlabscalesubtable`.`Result`
,COALESCE(NULL, 'Running') AS TYPE
, `tblgrn`.`Comp_Code`
, `tblgrn`.`Unit_Code`
, `tblgrn`.`UserId`
FROM
`tblgrn`
INNER JOIN `invlabtesscale`
ON (`tblgrn`.`InitialLabNo` = `invlabtesscale`.`IniLabNo`)
INNER JOIN `invlabscalesubtable`
ON (`invlabtesscale`.`Code` = `invlabscalesubtable`.`Code`)
INNER JOIN `invlabmaterial`
ON (`invlabscalesubtable`.`TestCode` = `invlabmaterial`.`Code`)));
this is the error message:
Error Code: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION
SELECT
tblgrn.InitialLabNo
, invlabtesscale.Code AS LabNo' at line 22
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0.018 sec
Remove the bracket between UNION and SELECT.
UNION
(SELECT
should be
UNION
SELECT
You may need to remove the closing bracket too.