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
Related
Here is my query:
SELECT 2016step2a1.id_step2a1, 2016step2a1.camperLast, 2016step2a1.camperFirst,
2016step2a1.camperGender, 2016step2a1.camperAge, 2016step2a1.guardName,
2016step2a1.guardCellphone, 2016step2a1.camperAddress, 2016step2a1.camperApartment,
2016step2a1.camperCity, 2016step2a1.camperState, 2016step2a1.camperZip,
2016step2a1.guardEmail, 2016step2a1.camperDiag, 2016step2a6.shirtT
FROM 2016step2a1
LEFT JOIN 2016step2a6 ON 2016step2a1.user_id = 2016step2a6.user_id
LEFT JOIN 2016step2a4 ON 2016step2a1.user_id = 2016step2a4.user_id
LEFT JOIN 2016step2a5 ON 2016step2a1.user_id = 2016step2a5.user_id
WHERE 2016step2a1.whichCamp = CampIAM
Can someone please help me figure out why this wont run?
Change your where clause to properly quote the right hand side value.
WHERE 2016step2a1.whichCamp = 'CampIAM'
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;
I am trying to update a table in my database from another table. Here is my Syntax, but I can't seem to find any issues with it. I keep getting SQL Error (1064).
UPDATE customers b
SET customers.takerid = customer_update_2016.ot
FROM customer_update_2016 a, customers b
WHERE a.phone = b.phone && a.lname = b.lname
SQL 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 'FROM customer_update_2016 a, customers b WHERE a.phone = b.phone & a.lname =b' at line 3
Solution:
UPDATE customers
INNER JOIN customer_update_2016
ON customers.phone = customer_update_2016.phone
AND customers.lname = customer_update_2016.lname
SET customers.takerid = customer_update_2016.ot
you have both mysql and sql-server
which one?
UPDATE customers
SET customers.takerid = customer_update_2016.ot
FROM customers
JOIN customer_update_2016
on customers.phone = customer_update_2016.phone
and customers.lname = customer_update_2016.lname
and customers.takerid <> customer_update_2016.ot
Follow something like this always
UPDATE [table1_name] AS t1
INNER JOIN [table2_name] AS t2
ON t1.[column1_name] = t2.[column1_name]
SET t1.[column2_name] = t2.[column2_name];
To solve your problem you should use JOIN, in my case I had to pass data from one table to another like you and this was the way that solved my problem, hope it help with yours and others.(I'm using MariaDB v10.4)
UPDATE
table1
LEFT JOIN table2 AS tb2
ON tb2.fieldThatJoin = table1.fieldThatJoin//this part indicate the field that join them
SET
table1.field1 = tb2.field1;
//if you want to update more than one field then do this
table1.field1 = tb2.field1,
table1.field2 = tb2.field2,
table1.field3 = tb2.field3;//remember to put the ';' at the end
I have a problem with my SQL. I would like to use a select to make an update, but so far I haven't been able to acomplish it. I would really apreciate if anyone could please help me. I'm quite new at MySQL. THe query in question is this:
UPDATE
pac
SET
pac.pac_spc_id = dtn_atual.spc_id
FROM
pac_paciente pac
INNER JOIN ( SELECT
dtn.dtn_pac_id,
spc_id
FROM `pac_destino` dtn
INNER JOIN ( select
des.dtn_pac_id,
MAX(CONCAT(des.dtn_data, des.dtn_seq)) AS datamax
FROM pac_destino des
GROUP BY des.`dtn_pac_id`
) AS d1 ON d1.dtn_pac_id = dtn.dtn_pac_id
AND d1.datamax = CONCAT(dtn.dtn_data, dtn.dtn_seq)
LEFT JOIN pac_classdestino c1 ON c1.cdo_id = dtn.dtn_cdo_id
LEFT JOIN pac_statuspaciente spc ON spc.spc_id = c1.cdo_spc_id
) AS dtn_atual on dtn_atual.dtn_pac_id = pac.`pac_id`
The error generated is
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 'FROM pac_paciente pac INNER JOIN ( SELECT
dtn.dtn_pac_id, spc_id
' at line 5
I am using two joins on the same table for two different select statements. I am wanting to implement an IF function, due to the fact that the table may contain a zero, I am wanting to substitue the zero for the word 'None'
Here is my SQL that works:
SELECT
CONCAT(`payments`.`AssignedTo`," - ",`people2`.`FName`," ",`people2`.`LName`) AS `AssignedTo`,
CONCAT(`payments`.`PersonID`," - ",`people`.`FName`," ",`people`.`LName`) AS `PersonName`
FROM `mb_payments` as `payments`
LEFT JOIN `mb_people` AS `people` ON `people`.`PersonID` = `payments`.`PersonID`
LEFT JOIN `mb_people` AS `people2` ON `people2`.`PersonID` = `payments`.`AssignedTo`
Here is my SQL with the IF function that does not work:
SELECT
IF(AssignedTo IS 0,'None', CONCAT(`payments`.`AssignedTo`," - ",`people2`.`FName`," ",`people2`.`LName`)),
CONCAT(`payments`.`PersonID`," - ",`people`.`FName`," ",`people`.`LName`) AS `PersonName`
FROM `mb_payments` as `payments`
LEFT JOIN `mb_people` AS `people` ON `people`.`PersonID` = `payments`.`PersonID`
LEFT JOIN `mb_people` AS `people2` ON `people2`.`PersonID` = `payments`.`AssignedTo`
You can use CASE statement in this case or if you want to use IF statement then your statement is wrong.
It should be:
SELECT
IF(AssignedTo = 0,'None', CONCAT(`payments`.`AssignedTo`," - ",`people2`.`FName`," ",`people2`.`LName`)) AS Result,
CONCAT(`payments`.`PersonID`," - ",`people`.`FName`," ",`people`.`LName`) AS `PersonName`
FROM `mb_payments` as `payments`
LEFT JOIN `mb_people` AS `people` ON `people`.`PersonID` = `payments`.`PersonID`
LEFT JOIN `mb_people` AS `people2` ON `people2`.`PersonID` = `payments`.`AssignedTo`
Check out this blog: http://timmurphy.org/2009/08/13/inline-if-and-case-statements-in-mysql/
I think you want ".. = 0", not "... IS 0". You use IS when comparing with NULL.