MYSQL Update Query syntax error 28-10-2016a - mysql

UPDATE DFEntryValues
SET DFEntryValues.DFFieldvalue = NOW()
FROM DFEntryValues
JOIN DFEntries ON DFEntryValues.DFEntryID = DFEntries.DFEntryID
JOIN DynamicFormStructures ON DFEntries.DynamicFormStructureID = DynamicFormStructures.DynamicFormStructureID
JOIN Projects ON DynamicFormStructures.ProjectID = Projects.ProjectId
JOIN Clients ON Projects.ClientID = Clients.ClientID
JOIN DFFieldDefinition ON DFEntryValues.DFFieldDefinitionID = DFFieldDefinition.DFFieldDefinitionID
WHERE Clients.ClientID = '26' AND DFFieldDefinition.label = 'Geboortedatum';
I get the following error:
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 'WHERE Clients.ClientID = '26' AND DFFieldDefinition.label = 'Geboortedatum' SET' at line 12
Can someone point me out what's wrong with this query?
Kind regards!!

It seems you are not using correct format.
Hope this helps.
UPDATE DFEntryValues JOIN DFEntries ON DFEntryValues.DFEntryID = DFEntries.DFEntryID
JOIN DynamicFormStructures ON DFEntries.DynamicFormStructureID = DynamicFormStructures.DynamicFormStructureID
JOIN Projects ON DynamicFormStructures.ProjectID = Projects.ProjectId
JOIN Clients ON Projects.ClientID = Clients.ClientID
JOIN DFFieldDefinition ON DFEntryValues.DFFieldDefinitionID = DFFieldDefinition.DFFieldDefinitionID
SET DFEntryValues.DFFieldvalue = NOW()
WHERE Clients.ClientID = '26' AND DFFieldDefinition.label = 'Geboortedatum';

Related

how is the syntax of using NOT EXISTS in mysql?

I got error message :
Query 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 'AS ChildCnt from tbl_user_master u WHERE u.sponsor_id = '145' AND u.user_type = ' at line 4 - Invalid query: select u.user_id,(SELECT COUNT(o.user_id) FROM tbl_user_master o WHERE o.sponsor_id = u.user_id AND o.user_type = 2 AND o.status =1 AND NOT EXISTS (
mysql code :
$user_tree = $this->getAllRec("u.user_id,(SELECT COUNT(o.user_id) FROM tbl_user_master o WHERE o.sponsor_id = u.user_id AND o.user_type = 2 AND o.status = 1 AND NOT EXISTS (
SELECT p.user_id
FROM tbl_flamingo_product_order p
WHERE o.user_id = p.user_id AND p.status=3) AS ChildCnt",
"tbl_user_master u",
"WHERE u.sponsor_id = '".$user_id."' AND u.user_type = 2 AND u.status =1");
May you help me find out where is the syntax error?
it is ok. I found it.
just replace
status=3)
to
status=3))

What is the correct syntax?

I wrote a sql query to update data of 'tbl_products'.
Here is the query
update tbl_products
set product_count = (product_count - tbl_order_details.product_sales_quantity)
from tbl_products
join tbl_order_details on tbl_order_details.product_id = tbl_products.product_id
join tbl_order on tbl_order.order_id = tbl_order_details.order_id
where tbl_order.order_id = 54;
But it gives me the following error
"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'from tbl_products join tbl_order_details on tbl_order_details.product_id = tbl_p' at line 1"
Whats wrong here?
In MySQL, the correct syntax is:
update tbl_products p join
tbl_order_details od
on od.product_id = p.product_id join
tbl_order o
on o.order_id = od.order_id
set p.product_count = (p.product_count - od.product_sales_quantity)
where o.order_id = 54;

MySQL query to SQL Server query

I defined sql query and it runs with no problem on MySQL (I am using MySQL) , but when I am trying to execute it on client site (they uses SQL Server)
I am getting "Error: Incorrect syntax near 'si'." error message
Hope someone can help me to define right syntax.
The query is following:
update stepinstance si
inner join cesteplink l on si.id = l.stepinstance_id
inner join prompt p on si.prompt_id = p.id
set si.principal_id = 29160180
where l.case_id = 29179541
and si.principal_id = 1799409
and si.status = 'In Progress'
set has to be before the join conditions.
update si
set si.principal_id = 29160180
from stepinstance si
inner join cesteplink l on si.id = l.stepinstance_id
inner join prompt p on si.prompt_id = p.id
where l.case_id = 29179541
and si.principal_id = 1799409
and si.status = 'In Progress'

Update field inner join

If i run this query i am getting an error:
What do i do wrong?
Query:
UPDATE cscart_profile_fields.value
SET cscart_profile_fields_data.value = '0'
FROM cscart_profile_fields_data
INNER JOIN cscart_user_profiles
ON cscart_profile_fields_data.object_id = cscart_user_profiles.profile_id
WHERE
where cscart_user_profiles.user_id = 5316 and
(
cscart_profile_fields_data.field_id = 65
or
cscart_profile_fields_data.field_id = 66)
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 cscart_profile_fields_data INNER JOIN cscart_user_profiles ' at line 3
Try this:::
UPDATE cscart_profile_fields_data
INNER JOIN cscart_user_profiles
ON cscart_profile_fields_data.object_id = cscart_user_profiles.profile_id
SET cscart_profile_fields_data.value = '0'
where cscart_user_profiles.user_id = 5316 and
(
cscart_profile_fields_data.field_id = 65
or
cscart_profile_fields_data.field_id = 66)

UPDATE and JOIN causing a Syntax Error in MySQL

UPDATE default_weekly_stats s
INNER JOIN default_profiles p
ON p.user_id = s.user_id
WHERE (default_profiles.opid = 0 OR default_profiles.opid IS NULL)
AND s.week = `1`
AND s.correct_picks = `4`
SET s.rank = 1
That's my query and I'm getting an 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 'WHERE (default_profiles.opid = 0 OR default_profiles.opid IS NULL) AND s.week = ' at line 1
The syntax looks right to me, but clearly I'm missing something. Any ideas what?
WHERE comes after SET
UPDATE default_weekly_stats s
INNER JOIN default_profiles p ON p.user_id = s.user_id
SET s.rank = 1
WHERE (default_profiles.opid = 0 OR default_profiles.opid IS NULL)
AND s.week = 1
AND s.correct_picks = 4
And as #Chad mentioned: Leave the backticks. You could use quotes but don't need any delimiter for numbers.
Look at the UPDATE Syntax
Try this:
UPDATE
default_weekly_stats s
INNER JOIN default_profiles p
ON p.user_id = s.user_id
SET s.rank = 1
WHERE (default_profiles.opid = 0 OR default_profiles.opid IS NULL)
AND s.week = `1`
AND s.correct_picks = `4`