I need some help with the query below - I am trying to pull information regarding price and multiply with the quantity & insert the sum into the table. So far I have,
update passenger_baggage
SET passenger_baggage.total_baggage_cost=passenger_baggage.passenger_baggage_quantity*baggage_type.baggage_type_cost
FROM passenger_baggage INNER JOIN baggage_type
ON passenger_baggage.passenger_baggage_id = baggage_type.baggage_type_id
WHERE passenger_id = "3";
and getting this 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 passenger_baggage INNER JOIN baggage_type ON
passenger_baggage.passenge...' at line 3
Expecting the query to multiply the two values & insert the total.
There is no FROM clause in an UPDATE query.
Try with this modified query:
update passenger_baggage
INNER JOIN baggage_type
ON passenger_baggage.passenger_baggage_id = baggage_type.baggage_type_id
SET passenger_baggage.total_baggage_cost = passenger_baggage.passenger_baggage_quantity * baggage_type.baggage_type_cost
WHERE passenger_id = "3";
Try this:
UPDATE passenger_baggage, baggage_type
SET passenger_baggage.total_baggage_cost = passenger_baggage.passenger_baggage_quantity * baggage_type.baggage_type_cost
WHERE passenger_baggage.passenger_baggage_id = baggage_type.baggage_type_id AND passenger_id = "3";
Saw an example from the MySQL doc (https://dev.mysql.com/doc/refman/8.0/en/update.html)
Related
I got an error while updating the table with the join query. The error message is:
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 'from employee details join employeedept on employee details.emp_dept=employeedept.' at line 3
Can anyone help me to resolve this error?
update employeeDetails
set employeeDetails.emp_age = employeeDetails.emp_age+20, employeeDetails.emp_salary = employeeDetails.emp_salary-500
from employeeDetails
join employeedept on employeeDetails.emp_dept = employeedept.dept_name
where employeedept.dept_name = 'CSE';
select * from employeeDetails;
List item
Have you tried using MySQL's UPDATE JOIN syntax yet? e.g.:
update employeeDetails
join employeeDept on employeeDetails.emp_dept = employeeDept.dept_name
set
employeeDetails.emp_age = employeeDetails.emp_age+20,
employeeDetails.emp_salary = employeeDetails.emp_salary-500
where employeeDept.dept_name = 'CSE';
select * from employeeDetails;
I'm trying to update columns based on two matching columns: firms.id = investors.firm and investors.firm_role = "ceo", but the server keeps rejecting my syntax. I have tried inner joins, without inner joins, it's all really too complex for me, so I'm not sure what to do next.
UPDATE firms
JOIN investors USING (firms.id = investors.firm)
SET firms.ceo = investors.name
WHERE investors.firm_role = "ceo"
Error:
SQL 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 '.id = investors.firm) SET firms.ceo = investors.name WHERE investors.firm_role =' at line 1
You are very close with your syntax:
UPDATE firms
LEFT JOIN investors ON firms.id = investors.firm
SET firms.ceo = investors.name
WHERE investors.firm_role = "ceo"
Refer to this.
Try this Syntax
update patients set column_name="value" where (condition)
for example im using c# and it goes
update patients set " + dgv.Columns[c].HeaderText + "='" + dgv.Rows[dgv.CurrentCell.RowIndex].Cells[c].Value.ToString() + "' where idno='" + dgv.Rows[dgv.CurrentCell.RowIndex].Cells[0].Value.ToString() + "'"
You may try this
UPDATE firms
INNER JOIN investors ON firms.id = investors.firm AND investors.firm_role = "ceo"
SET firms.ceo = investors.name
I have the following query that works great and shows me where the tbl_staff.staff_id and tbl_lead.rlog_create_user_id values do not match.
SELECT
tbl_staff.staff_id,
tbl_staff.username,
tbl_lead.rlog_create_user_name,
tbl_lead.rlog_create_user_id
FROM
tbl_staff
JOIN tbl_lead ON tbl_staff.username = tbl_lead.rlog_create_user_name
AND tbl_staff.staff_id <> tbl_lead.rlog_create_user_id;
The query returns values like this where you can see the 1014 does not match the 1004.
1014 bubba bubba 1004
I want to update the value in the tbl_lead.rlog_create_user_id to the same value as is found in tbl_staff.staff_id.
I tried to insert a SET command but it's giving me a generic syntax error:
SELECT
tbl_staff.staff_id,
tbl_staff.username,
tbl_lead.rlog_create_user_name,
tbl_lead.rlog_create_user_id
FROM
tbl_staff
JOIN tbl_lead ON tbl_staff.username = tbl_lead.rlog_create_user_name
AND tbl_staff.staff_id <> tbl_lead.rlog_create_user_id
SET tbl_lead.rlog_create_user_id=tbl_staff.staff_id ;
The actual error is:
[Err] 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 'SET tbl_lead.rlog_create_user_id=tbl_staff.staff_id' at line
10
I tried to change the SELECT to and UPDATE command using this question but still could not get it working: How can I do an UPDATE statement with JOIN in SQL?
Try this
UPDATE tbl_lead
JOIN tbl_staff ON tbl_staff.username = tbl_lead.rlog_create_user_name
SET tbl_lead.rlog_create_user_id = tbl_staff.staff_id
WHERE tbl_staff.staff_id <> tbl_lead.rlog_create_user_id;
Have you tried like this ?
UPDATE tbl_staff, tbl_lead
SET tbl_lead.rlog_create_user_id = tbl_staff.staff_id
WHERE tbl_staff.username = tbl_lead.rlog_create_user_name
I keep getting this syntax error in my MySQL code within a PHP file. I'm simply trying to increment/add to the value already in the table with this time variable. If anyone could help me out I'd greatly appreciate it.
PHP:
$sql = "UPDATE Aircraft
SET MaintenanceFlightTime = (MaintenanceFlightTime + $MaintenanceDuration),
WHERE AircraftID = $AircraftID";
Error:
UPDATE Aircraft SET MaintenanceFlightTime = (MaintenanceFlightTime + 00:10:00), WHERE AircraftID = 8
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 ':10:00), WHERE AircraftID = 8' at line 2
You cannot just add a string like '01:01:01' to a time column but you can use ADDTIME()
$MaintenanceDuration = '00:10:00';
$sql = "UPDATE Aircraft
SET MaintenanceFlightTime = ADDTIME(MaintenanceFlightTime, '$MaintenanceDuration')
WHERE AircraftID = $AircraftID";
$produpd = "UPDATE tblnavpc SET tblnavpc.ChildName = tblnav.NavName " .
"FROM tblnav WHERE tblnavpc.CID = tblnav.NavID";
This is the error I get"
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 tblnav
WHERE tblnavpc.CID = tblnav.NavID' at
line 1
I know keys aren't named greatly but I just trying to fix this one problem, I didn't name the tables.
You don't have a FROM clause in an update:
UPDATE tblnavpc
INNER JOIN tblnav ON tblnavpc.CID = tblnav.NavID
SET tblnavpc.ChildName = tblnav.NavName
"From" cannot be used with update statements.
Should be
$produpd = "UPDATE tblnavpc SET tblnavpc.ChildName = tblnav.NavName " .
"WHERE tblnavpc.CID = tblnav.NavID";