i want to compare two tables by inner join and update the columns in table d_family by edit_27_5 table columns ..but something wrong..i tried more solution but it ditint work good
i see this message ( #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 d_family.city = edit_27_5.city, SET d_family.fa_name = edit_27_5.fa_n' at line 3)
UPDATE d_family INNER JOIN edit_27_5
ON
d_family.fa_id = edit_27_5.fa_id
SET d_family.area = edit_27_5.area,
SET d_family.city = edit_27_5.city,
SET d_family.fa_name = edit_27_5.fa_name,
SET d_family.fa_nationality = edit_27_5.nath,
SET d_family.fa_phone_number = edit_27_5.phone,
SET d_family.fa_mobile_number = edit_27_5.mobile,
SET d_family.fa_account_anstaqram = edit_27_5.anst,
SET d_family.fa_account_mail = edit_27_5.email,
SET d_family.fa_account_twitter = edit_27_5.twit,
SET d_family.fa_account_facebook = edit_27_5.face,
SET d_family.fa_product_desc = edit_27_5.pt_desc,
SET d_family.product_type = edit_27_5.pt_type,
SET d_family.fa_markting_type = edit_27_5.markting
WHERE d_family.fa_id < 7221
UPDATE d_family INNER JOIN edit_27_5
ON
d_family.fa_id = edit_27_5.fa_id
You were missing the joining part
d_family.fa_id = .fa_id
Also its wrong to have set multiple time
So the syntax is
update table1 t1
join table2 t2 on t1.id = t2.id
set
t1.col1 = t2.col1,
t1.col2 = t2.col,
......
In your case it should be something as
UPDATE d_family
INNER JOIN edit_27_5 ON d_family.fa_id = edit_27_5.fa_id
SET
d_family.area = edit_27_5.area,
d_family.city = edit_27_5.city,
d_family.fa_name = edit_27_5.fa_name,
d_family.fa_nationality = edit_27_5.nath,
d_family.fa_phone_number = edit_27_5.phone,
d_family.fa_mobile_number = edit_27_5.mobile,
d_family.fa_account_anstaqram = edit_27_5.anst,
d_family.fa_account_mail = edit_27_5.email,
d_family.fa_account_twitter = edit_27_5.twit,
d_family.fa_account_facebook = edit_27_5.face,
d_family.fa_product_desc = edit_27_5.pt_desc,
d_family.product_type = edit_27_5.pt_type,
d_family.fa_markting_type = edit_27_5.markting
WHERE d_family.fa_id < 7221
Related
I'm trying to update data in my table.
I have two tables, t1 and t2
T1
T2
I'm want to do, that if t1 have id_avito = null and all_usl_name = %usl_name1% and all_tel = %tel1%, and t2 have id != null, usl_name = %usl_name1% and tel = %tel1%
For example, t1 after execute query must to look like that
update people.t1, people.t2
set
id_avito = people.t2.id,
lnk_avito = people.t2.link,
all_price = people.t2.price,
all_date = people.t2.date,
all_adr = people.t2.adr,
all_usl_name = people.t2.usl_name
where id_avito != people.t2.id
and all_tel= people.t2.tel
and all_usl_type = people.t2.usl_type
I try to do like this, but it is not working
UPD
EXAMPLE: tables. Table before update, after update, and second table
Try with update join also you need to use like operator where you are searching with string
update people.t1 a
join people.t2 on id_avito != people.t2.id
and all_tel= people.t2.tel
and all_usl_type = people.t2.usl_type
set
id_avito = people.t2.id,
lnk_avito = people.t2.link,
all_price = people.t2.price,
all_date = people.t2.date,
all_adr = people.t2.adr,
all_usl_name = people.t2.usl_name
Please try this.
For SQL
UPDATE A
SET
A.id_avito = B.id,
A.lnk_avito = B.link,
A.all_price = B.price,
A.all_date = B.date,
A.all_adr = B.adr,
A.all_usl_name = B.usl_name
FROM
people.t1 A
INNER JOIN people.t2 B
ON A.id_avito != B.id
AND A.all_tel= B.tel
AND A.all_usl_type =B.usl_type
where ISNULL(A.id_avito,'') ='' and A.all_usl_name like '%usl_name1%' and A.all_tel like '%tel1%' and B.id is not null and B.usl_name like '%usl_name1%' and B.tel like '%tel1%'
FOR MYSQL
UPDATE people.t1 a
INNER JOIN people.t2 B
ON A.id_avito != B.id
AND A.all_tel= B.tel
AND A.all_usl_type =B.usl_type
SET
A.id_avito = B.id,
A.lnk_avito = B.link,
A.all_price = B.price,
A.all_date = B.date,
A.all_adr = B.adr,
A.all_usl_name = B.usl_name
where IFNULL(A.id_avito,'') = '' and A.all_usl_name like '%usl_name1%' and A.all_tel like '%tel1%' and IFNULL(B.id,0) <> 0 and B.usl_name like '%usl_name1%' and B.tel like '%tel1%'
Query
I'm trying to executing the below query but in my phpmyadmin says
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 eest_estimated_total pet INNER JOIN eest_total pt ON pt.OrderNo = pet.Order' at line 1
UPDATE eest_estimated_total
SET pet.Freight = pt.FrieghtCost, pet.CustomDuty = pt.ImportDuty
FROM eest_estimated_total pet
INNER JOIN eest_total pt
ON pt.OrderNo = pet.OrderNo
WHERE pt.OrderNo = pet.OrderNo
So may i know where im doing wrong ?
Try this way:
UPDATE pipo_estimated_total AS pet
INNER JOIN pipo_total AS pt
ON pt.OrderNo = pet.OrderNo
SET pet.Freight = pt.FrieghtCost, pet.CustomDuty = pt.ImportDuty
WHERE pt.OrderNo = pet.OrderNo
As the answer says: update-from-select-using-sql-server
UPDATE
Table_A
SET
Table_A.col1 = Table_B.col1,
Table_A.col2 = Table_B.col2
FROM
Some_Table Table_A
INNER JOIN
Other_Table Table_B
ON
Table_A.id = Table_B.id
WHERE
Table_A.col3 = 'cool'
Your Answer:
UPDATE pet
SET pet.Freight = pt.FrieghtCost, pet.CustomDuty = pt.ImportDuty
FROM eest_estimated_total pet
INNER JOIN eest_total pt
ON pt.OrderNo = pet.OrderNo
WHERE pt.OrderNo = pet.OrderNo
Run This Query :-
UPDATE pipo_estimated_total
SET pet.Freight = pt.FrieghtCost, pet.CustomDuty = pt.ImportDuty
FROM pipo_estimated_total AS pet
INNER JOIN pipo_total pt
ON pt.OrderNo = pet.OrderNo
WHERE pt.OrderNo = pet.OrderNo
I get the error [Err] 1066 - Not unique table/alias: 'vtiger_leadscf'
UPDATE vtigerdb.vtiger_leadscf
JOIN vtiger_new.vtiger_leaddetails ON vtiger_new.vtiger_leadscf.leadid = vtiger_new.vtiger_leaddetails.leadid
JOIN vtiger_new.vtiger_leadaddress ON vtiger_new.vtiger_leadaddress.leadaddressid = vtiger_new.vtiger_leadscf.leadid
JOIN vtiger_new.vtiger_crmentity ON vtiger_new.vtiger_crmentity.crmid = vtiger_new.vtiger_leadscf.leadid
JOIN vtiger_new.vtiger_users ON vtiger_new.vtiger_users.id = vtiger_new.vtiger_crmentity.smcreatorid
JOIN vtigerdb.vtiger_leadscf ON vtigerdb.vtiger_leadscf.leadid = vtiger_new.vtiger_leadscf.leadid
SET vtigerdb.vtiger_leadscf.cf_953 = CONCAT(vtiger_new.vtiger_users.first_name,' ',vtiger_new.vtiger_users.last_name)
WHERE vtigerdb.vtiger_leadscf.leadid = vtiger_new.vtiger_leadscf.leadid
AND cf_953 = ""
can't figure out whats wrong with it.
Last join and update reference the same table.
Use JOIN table AS other_name to avoid this problem.
Here is the corrected query.
Plus I think you meant vtiger_new on the last join and not vtigerdb as you wrote.
UPDATE vtigerdb.vtiger_leadscf
JOIN vtiger_new.vtiger_leaddetails ON vtiger_new.vtiger_leadscf.leadid = vtiger_new.vtiger_leaddetails.leadid
JOIN vtiger_new.vtiger_leadaddress ON vtiger_new.vtiger_leadaddress.leadaddressid = vtiger_new.vtiger_leadscf.leadid
JOIN vtiger_new.vtiger_crmentity ON vtiger_new.vtiger_crmentity.crmid = vtiger_new.vtiger_leadscf.leadid
JOIN vtiger_new.vtiger_users ON vtiger_new.vtiger_users.id = vtiger_new.vtiger_crmentity.smcreatorid
JOIN vtiger_new.vtiger_leadscf AS vlead ON vtigerdb.vtiger_leadscf.leadid = vlead.leadid
SET vtigerdb.vtiger_leadscf.cf_953 = CONCAT(vtiger_new.vtiger_users.first_name,' ',vtiger_new.vtiger_users.last_name)
WHERE vtigerdb.vtiger_leadscf.leadid = vlead.leadid
AND cf_953 = ""
I am trying to write a query that performs an inner join within an update statement.
Here is the current query I am working with:
UPDATE
singulation1.`q096_cq33r08-ds01-n-testtable`
SET
visual = t2.visual,
inspection_status = t2.inspection_status,
inspector_name = t2.inspector_name
FROM
singulation1.`q096_cq33r08-ds01-n-testtable` t1
INNER JOIN
singulation1.`q014_bq31t05-dw30-x` t2
ON
(t1.print = t2.print AND t1.id3 = t2.id3);
Something about MySql does not like the FROM clause.
For updates, you specify the join in the update clause
UPDATE
singulation1.`q096_cq33r08-ds01-n-testtable` AS t1
INNER JOIN singulation1.`q014_bq31t05-dw30-x` AS t2
ON t1.print = t2.print AND t1.id3 = t2.id3
SET
t1.visual = t2.visual
t1.inspection_status = t2.inspection_status,
t1.inspector_name = t2.inspector_name
I am trying to update a field value in a mysql database using a select query with inner join
I currently get
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 'AS cc WHERE cc.account_id = na.account_id' at line 5
UPDATE accounts AS na
SET na.pdm_id = (
SELECT cp.person_id FROM `temp_accounts` AS ta INNER JOIN call_managment_system.accounts AS a ON ta.company_code = a.company_code
INNER JOIN contact_personal AS cp ON cp.name = ta.FSM AND contact_link = 'PDM'
)
WHERE a.account_id = na.account_id
How can I fix this query to work? I want to update the field called pdm_id to set it equal to cp.person_id
Thanks
UPDATE accounts na
INNER JOIN call_managment_system.accounts a
ON a.account_id = na.account_id
INNER JOIN temp_accounts ta
ON ta.company_code = a.company_code
INNER JOIN contact_personal cp
ON cp.name = ta.FSM
SET na.pdm_id = cp.person_id
WHERE contact_link = 'PDM'