I try to a run a specific query. However, when I execute it, the MySQL server doesn't respond anymore.
There is approximately 30000 rows in the table base_contrats_actifs but I don't know if this is a problem.
Here is the query :
UPDATE
base_contrats_actifs a
SET
a.code_indice = (
SELECT
MAX(g.code_indice)
FROM
base_gid g
WHERE
a.num_version = g.num_version_contrat
),
a.flag_bailleur_locataire = (
SELECT
MAX(g.flag_bailleur_locataire)
FROM
base_gid g
WHERE
a.num_version = g.num_version_contrat
),
a.compte_client = (
SELECT
MAX(g.compte_client)
FROM
base_gid g
WHERE
a.num_version = g.num_version_contrat
)
Can you see if there is an error ? If not, is there any way to debug the query ?
I don't know exactly why your update is non performant, but given the number of correlated subqueries you have, I'm not surprised. Try rewriting it as an update join:
UPDATE base_contrats_actifs a
INNER JOIN
(
SELECT
num_version_contrat,
MAX(code_indice) AS max_code_indice,
MAX(flag_bailleur_locataire) AS max_flag_bailleur_locataire,
MAX(compte_client) AS max_compte_client
FROM base_gid
GROUP BY num_version_contrat
) g
ON a.num_version = g.num_version_contrat
SET
a.code_indice = g.max_code_indice,
a.flag_bailleur_locataire = g.max_flag_bailleur_locataire,
a.compte_client = g.max_compte_client;
I need to add a join 'level' to a pre-existing SQL query... unfortunately I keep getting errors with this query. I'm proabably falling somewhere but I cannot understand how to fix it.
The original query is the following:
SELECT
noleggio.*,
nome AS convenzionato
FROM
anag_convenzionati
RIGHT JOIN (SELECT
noleggio.*, targa, dc_standard AS dcstandard
FROM
veicoli_contratti
RIGHT JOIN (SELECT
noleggio.*,
nome AS assicurazione_pagante
FROM
anag_assicurazioni
RIGHT JOIN (SELECT
fatt_sconto_noleggio,
fatt_prezzo_noleggio,
id AS idnoleggio,
numero,
serie,
id_convenzionato,
stato_noleggio,
modalita_noleggio,
conducente,
locatario,
locazione_in_proprio,
id_assicurazione_pagante,
id_veicolo,
giorni,
fatt_giorni_noleggio,
fatt_prezzo_totale_noleggio,
data_pagamento_cliente_a_convenzionato,
ore_manodopera,
IF(locazione_in_proprio = 1, conducente, locatario) AS cedente
FROM
noleggio_veicoli
WHERE
((data_cancellazione IS NULL) OR (data_cancellazione = ''))
) AS noleggio ON noleggio.id_assicurazione_pagante = anag_assicurazioni.id
) AS noleggio ON noleggio.id_veicolo = veicoli_contratti.id
) AS noleggio ON noleggio.id_convenzionato = anag_convenzionati.id;
I need to join the resulting table with moduli_ocr table in this way:
SELECT
noleggio.*
FROM
(//query//) AS noleggio
LEFT JOIN
moduli_ocr ON moduli_ocr.id_noleggio = noleggio.id;
Where //query// is the code above.
The error I got (running the query in MySQL Workbench is:
Error Code: 1054. Unknown column 'noleggio.id' in 'on clause'
BTW I'm not sure if I have to use RIGHT or LEFT join but I will check this once the query is properly 'running'.
Best regards.
It seems that you assign idnoleggio alias to the field "id". Try joining on
moduli_ocr.id_noleggio = noleggio.idnoleggio;
SELECT PRODDTA.F4006.OADOCO, PRODDTA.F4006.OADCTO, PRODDTA.F4006.OAKCOO, PRODDTA.F4006.OAANTY, PRODDTA.F4006.OAMLNM, PRODDTA.F4006.OAADD1, PRODDTA.F4006.OAADD2, PRODDTA.F4006.OAADD3, PRODDTA.F4006.OAADD4, PRODDTA.F4006.OAADDZ, PRODDTA.F4006.OACTY1, PRODDTA.F4006.OACOUN, PRODDTA.F4006.OAADDS, PRODDTA.F4006.OACRTE, PRODDTA.F4006.OABKML, PRODDTA.F4006.OACTR, PRODDTA.F4006.OAUSER, PRODDTA.F4006.OAPID, PRODDTA.F4006.OAUPMJ, PRODDTA.F4006.OAJOBN, PRODDTA.F4006.OAUPMT, PRODDTA.F4006.OALNID
INTO #BAF4006ShipTo
FROM PRODDTA.F4006
WHERE (PRODDTA.F4006.OAANTY='2');
SELECT PRODDTA.F4211.SDKCOO, PRODDTA.F4211.SDDOCO, PRODDTA.F4211.SDDCTO, PRODDTA.F4211.SDAN8, PRODDTA.F4211.SDSHAN, PRODDTA.F4211.SDDOC, PRODDTA.F4211.SDDCT, PRODDTA.F4211.SDNXTR
INTO #BAFSumF4211byInvoice
FROM PRODDTA.F4211
GROUP BY PRODDTA.F4211.SDKCOO, PRODDTA.F4211.SDDOCO, PRODDTA.F4211.SDDCTO, PRODDTA.F4211.SDAN8, PRODDTA.F4211.SDSHAN, PRODDTA.F4211.SDDOC, PRODDTA.F4211.SDDCT, PRODDTA.F4211.SDNXTR
HAVING ((PRODDTA.F4211.SDKCOO='00035') AND (PRODDTA.F4211.SDNXTR='999'));
SELECT PRODDTA.F0018.TDCO, PRODDTA.F0018.TDDCTO, PRODDTA.F0018.TDDOCO, PRODDTA.F0018.TDAN8, PRODDTA.F0101.ABALPH, PRODDTA.F0116.ALADDS, (PRODDTA.F0018.TDAEXP/100) AS TDAEXP, (PRODDTA.F0018.TDATXN/100) AS TDATXN, (PRODDTA.F0018.TDATXA/100) AS TDATXA, (PRODDTA.F0018.TDSTAM/100) AS TDSTAM, PRODDTA.F0018.TDTXA1, PRODDTA.F0018.TDEXR1, PRODDTA.F0018.TDDGL, PRODDTA.F0018.TDDSVJ
INTO #BAFTaxQuery
FROM (PRODDTA.F0018 INNER JOIN PRODDTA.F0101 ON PRODDTA.F0018.TDAN8 = PRODDTA.F0101.ABAN8) INNER JOIN PRODDTA.F0116 ON PRODDTA.F0018.TDAN8 = PRODDTA.F0116.ALAN8
WHERE ((PRODDTA.F0018.TDCO='00035') AND (PRODDTA.F0018.TDDCTO='RI') AND (PRODDTA.F0018.TDDGL>114182 And PRODDTA.F0018.TDDGL<=114273));
SELECT #BAFTaxQuery.TDCO, #BAFTaxQuery.TDDCTO, #BAFTaxQuery.TDDOCO, #BAFSumF4211byInvoice.SDDOCO, #BAFSumF4211byInvoice.SDDCTO, #BAFTaxQuery.TDAN8, #BAFTaxQuery.ABALPH, #BAFTaxQuery.ALADDS, #BAFSumF4211byInvoice.SDSHAN, #BAFTaxQuery.TDAEXP, #BAFTaxQuery.TDATXN, #BAFTaxQuery.TDATXA, #BAFTaxQuery.TDSTAM, #BAFTaxQuery.TDTXA1, #BAFTaxQuery.TDEXR1, #BAFTaxQuery.TDDGL, #BAFTaxQuery.TDDSVJ
INTO #BAFTaxQuery2
FROM #BAFTaxQuery LEFT JOIN #BAFSumF4211byInvoice ON (#BAFTaxQuery.TDDOCO = #BAFSumF4211byInvoice.SDDOC) AND (#BAFTaxQuery.TDDCTO = #BAFSumF4211byInvoice.SDDCT);
SELECT #BAFTaxQuery2.TDCO, #BAFTaxQuery2.TDDCTO, #BAFTaxQuery2.TDDOCO, #BAFTaxQuery2.SDDOCO, #BAFTaxQuery2.SDDCTO, #BAFTaxQuery2.TDAN8, #BAFTaxQuery2.ABALPH as BAFTaxQuery2_ABALPH, #BAFTaxQuery2.ALADDS as BAFTaxQuery2_ALADDS, #BAFTaxQuery2.SDSHAN,PRODDTA.F0101.ABALPH as BAFTaxQuery3_ABALPH, PRODDTA.F0116.ALADDS as BAFTaxQuery3_ALADDS, #BAFTaxQuery2.TDAEXP, #BAFTaxQuery2.TDATXN, #BAFTaxQuery2.TDATXA, #BAFTaxQuery2.TDSTAM, #BAFTaxQuery2.TDTXA1, #BAFTaxQuery2.TDEXR1, #BAFTaxQuery2.TDDGL, #BAFTaxQuery2.TDDSVJ
INTO #BAFTaxQuery3
FROM #BAFTaxQuery2 INNER JOIN PRODDTA.F0101 ON #BAFTaxQuery2.SDSHAN = PRODDTA.F0101.ABAN8 INNER JOIN PRODDTA.F0116 ON #BAFTaxQuery2.SDSHAN = PRODDTA.F0116.ALAN8;
SELECT #BAFTaxQuery3.TDCO, #BAFTaxQuery3.TDDCTO, #BAFTaxQuery3.TDDOCO, #BAFTaxQuery3.SDDOCO, #BAFTaxQuery3.SDDCTO, #BAFTaxQuery3.TDAN8, #BAFTaxQuery3.BAFTaxQuery2_ABALPH, #BAFTaxQuery3.BAFTaxQuery2_ALADDS, #BAFTaxQuery3.SDSHAN, #BAFTaxQuery3.BAFTaxQuery3_ABALPH, #BAFTaxQuery3.BAFTaxQuery3_ALADDS,#BAFTaxQuery3.TDAEXP, #BAFTaxQuery3.TDATXN, #BAFTaxQuery3.TDATXA, #BAFTaxQuery3.TDSTAM, #BAFTaxQuery3.TDTXA1, #BAFTaxQuery3.TDEXR1, #BAFTaxQuery3.TDDGL, #BAFTaxQuery3.TDDSVJ, #BAF4006ShipTo.OAMLNM, #BAF4006ShipTo.OACTY1, #BAF4006ShipTo.OAADDS
INTO #BAFTaxReportQuery
FROM #BAFTaxQuery3 LEFT JOIN #BAF4006ShipTo ON (#BAFTaxQuery3.SDDCTO = #BAF4006ShipTo.OADCTO) AND (#BAFTaxQuery3.SDDOCO = #BAF4006ShipTo.OADOCO) AND (#BAFTaxQuery3.TDCO = #BAF4006ShipTo.OAKCOO);
DROP TABLE #BAF4006ShipTo
DROP TABLE #BAFTaxQuery
DROP TABLE #BAFTaxQuery2
DROP TABLE #BAFSumF4211byInvoice
DROP TABLE #BAFTaxQuery3
DROP TABLE #BAFTaxReportQuery
The Query runs fine in Sql Server.
I create shared dataset as 'Text' and I'm able to create successfully.
But in the report when I Add Dataset , there are no fields showing.
I tried adding it manually too but get this error. "THe shared Dataset definition is not valid. The report definition element 'Dataset' is empty at line 43,position 5. It is missing a mandatory chid elemnt of type 'Fields.'"
I'm getting this following error:
MYSQL ERROR
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 'DISTINCT R.roomtype as roomtype , I1.meal_plan as
mealplan , I1.`bed_t' at line 3
My Code is
SELECT
DISTINCT H.`hotelname` as `hotelname` ,
DISTINCT R.`roomtype` as `roomtype` ,
I1.`meal_plan` as `mealplan` ,
I1.`bed_type` as `bedtype` ,
I1.`roomrate` as `roomrate` ,
I1.`pax` as `pax` ,
I1.`childrate` as `childrate` ,
I1.`childrate1` as `childrate1` ,
I1.`childrate2` as `childrate2` ,
I1.`childrate3` as `childrate3` ,
P.`profitmarkup_type` as `profit_type` ,
P.`applyprofit_val_room` as `applyprofit_val_room` ,
P.`applyprofit_val_bed` as `applyprofit_val_bed`
FROM `hoteldetails` H
INNER JOIN `roomdetails` R
on H.`hotelname` = R.`hotelname`
INNER JOIN `inventorypolicy` I1
on I1.`hotel_name` = H.`hotelname`
AND I1.`room_plan` = R.`roomtype`
AND I1.`bed_type`=R.`bedtype`
AND I1.`meal_plan`=R.`mealplan`
AND I1.`suppliername`=H.`supplier`
INNER JOIN `profitmarkup` P
on P.`hotel_name` = H.`hotelname`
AND P.`suppliername` = H.`supplier`
WHERE H.`active`='1'
AND H.`country`='MAL'
AND H.`city`='KL'
AND H.`show2web`='1'
AND H.`expiry_date` >= 11/09/2014
AND I1.`inventory_status`='1'
AND P.`markup_status` = '1'
AND 20140911 BETWEEN ((I1.`date1`)+(I1.`month1`*100)+(I1.`year1`*10000)) AND ((I1.`date2`)+(I1.`month2`*100)+(I1.`year2`*10000))
AND 20140911 BETWEEN ((P.`date1`)+(P.`month1`*100)+(P.`year1`*10000)) AND ((P.`date2`)+(P.`month2`*100)+(P.`year2`*10000))
I dont know how to fix this. Any help is greatly appreciated.
As you can learn from the documentation of the SELECT MySQL statement, DISTINCT can be placed before any field or expression to be selected. This automatically forces a single instance of it in a query.
And somewhere down the road there is a sentence that says everything:
DISTINCTROW is a synonym for DISTINCT.
Mysql Version Works
UPDATE results SET rCARRIER = (
SELECT cellCarrierName
FROM tblImportedTempTable, user, cellCarrier
WHERE
userEmployeeNumber = tblImportedTempTable.EMPLOYEENUMBER
AND userId = results.rUserId
AND results.rPHONENUMBER = tblImportedTempTable.PHONENUMBER
AND CARRIER = cellCarrierId )
I have written this sql that works fine in MySql(above) and fails in access 2003(below) any suggestions? Is one or both of the 2 nonstandard sql? Does Access hav an admin problem?
Sorry the field and table names are diferent this is the ACCESS version.
Access version
UPDATE tblWorkerPhoneNumber SET tblWorkerPhoneNumber.PhoneCarrier = (
SELECT PhoneCarrierType.CarrierName
FROM tblImportedPhoneCarrier, tblWorkerMaster, PhoneCarrierType
WHERE
tblWorkerMaster.EmployeeNumber = tblImportedPhoneCarrier.Emp
AND tblWorkerMaster.WorkerID = tblWorkerPhoneNumber.WorkerID
AND tblWorkerPhoneNumber.PhoneNumber = tblImportedPhoneCarrier.Cell
AND tblImportedPhoneCarrier.CarrierCode = PhoneCarrierType.CarrierID )
Error Message
Operation must use and updateable query
Thanks
In MS Access, something like this:
UPDATE tblWorkerPhoneNumber
INNER JOIN tblWorkerMaster ON tblWorkerMaster.WorkerID = tblWorkerPhoneNumber.WorkerID
INNER JOIN tblImportedPhoneCarrier ON tblWorkerPhoneNumber.PhoneNumber = tblImportedPhoneCarrier.Cell
INNER JOIN PhoneCarrierType ON tblImportedPhoneCarrier.CarrierCode = PhoneCarrierType.CarrierID
SET tblWorkerPhoneNumber.PhoneCarrier = PhoneCarrierType.CarrierName
WHERE tblWorkerMaster.EmployeeNumber = tblImportedPhoneCarrier.Emp
(Might need to change the join conditions; I'm not familiar with your schema)