mysql - Trasform this select with subquery in update -
i have following query:
select (select min(ifnull(lead2.id_father,lead2.id)) id_father leads lead2 lead2.telefone_residencial = lead1.telefone_residencial or lead2.telefone_residencial = lead1.telefone_celular or lead2.telefone_residencial = lead1.telefone_comercial or lead2.telefone_celular = lead1.telefone_residencial or lead2.telefone_celular = lead1.telefone_celular or lead2.telefone_celular = lead1.telefone_comercial or lead2.telefone_comercial = lead1.telefone_residencial or lead2.telefone_comercial = lead1.telefone_celular or lead2.telefone_comercial = lead1.telefone_comercial or lead2.email = lead1.email), lead1.id leads lead1 limit 1000
i need make this, update. tried failed.
update leads lead1 set id_father= (select min(ifnull(lead2.id_father,lead2.id)) leads lead2 lead2.telefone_residencial = lead1.telefone_residencial or lead2.telefone_residencial = lead1.telefone_celular or lead2.telefone_residencial = lead1.telefone_comercial or lead2.telefone_celular = lead1.telefone_residencial or lead2.telefone_celular = lead1.telefone_celular or lead2.telefone_celular = lead1.telefone_comercial or lead2.telefone_comercial = lead1.telefone_residencial or lead2.telefone_comercial = lead1.telefone_celular or lead2.telefone_comercial = lead1.telefone_comercial or lead2.email = lead1.email) limit 1000
when try run code, error, not doing update.
any suggestions, i've tried other ways, nothing far.
_______updated 07/24/2015_____________resolved_____________
update leads lead, (select (select min(ifnull(lead2.id_pai,lead2.id)) id_father leads lead2, empresas empr2 empr2.fk_grupos_id = empr1.fk_grupos_id and(lead2.telefone_residencial = lead1.telefone_residencial or lead2.telefone_residencial = lead1.telefone_celular or lead2.telefone_residencial = lead1.telefone_comercial or lead2.telefone_celular = lead1.telefone_residencial or lead2.telefone_celular = lead1.telefone_celular or lead2.telefone_celular = lead1.telefone_comercial or lead2.telefone_comercial = lead1.telefone_residencial or lead2.telefone_comercial = lead1.telefone_celular or lead2.telefone_comercial = lead1.telefone_comercial or lead2.email = lead1.email)) id_father, lead1.id leads lead1, empresas empr1 lead1.fk_empresas_id = empr1.id )as td set lead.id_pai = ifnull(td.id_father,td.id) lead.id = td.id
try this:
update lead1 set lead1.id_father= min(ifnull(lead2.id_father,lead2.id)) leads lead1, leads lead2 lead2.telefone_residencial = lead1.telefone_residencial or lead2.telefone_residencial = lead1.telefone_celular or lead2.telefone_residencial = lead1.telefone_comercial or lead2.telefone_celular = lead1.telefone_residencial or lead2.telefone_celular = lead1.telefone_celular or lead2.telefone_celular = lead1.telefone_comercial or lead2.telefone_comercial = lead1.telefone_residencial or lead2.telefone_comercial = lead1.telefone_celular or lead2.telefone_comercial = lead1.telefone_comercial or lead2.email = lead1.email)
Comments
Post a Comment