Last active
September 14, 2017 08:26
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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