Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save suresh-kumara-gist/378a070120e9b4fb3fe743aa51ecb868 to your computer and use it in GitHub Desktop.
Save suresh-kumara-gist/378a070120e9b4fb3fe743aa51ecb868 to your computer and use it in GitHub Desktop.
update field with other table data and case in mysql select query.
select nfd.nid,nfd.title, CASE casefield
WHEN 0 THEN '0'
WHEN 1 THEN '1'
ELSE NULL
END as casefieldalias
from table1 nfd
join table2 d on nfd.nid = d.tid
where title like '%<%' or title like '%>%' and type in ('testtype');
update field with other table data:
===================================
UPDATE table1 nfd
JOIN table2 d ON nfd.nid = d.t2id
SET nfd.title = (
CASE d.casefield
WHEN 0 THEN '0'
WHEN 1 THEN '1'
END)
where (nfd.title like '%<%' or nfd.title like '%>%') and nfd.type in ('testtype') and nfd.nid IN (37138,374988);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment