{"id":1077,"date":"2010-12-17T11:19:43","date_gmt":"2010-12-17T19:19:43","guid":{"rendered":"http:\/\/www.johnscarry.com\/blog\/?p=1077"},"modified":"2012-04-02T10:38:10","modified_gmt":"2012-04-02T17:38:10","slug":"things-i-cant-remember-mysql","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1077","title":{"rendered":"Things I can&#8217;t remember &#8211; MySQL"},"content":{"rendered":"<p>I&#8217;ll want to add a new field to a table and I have the data in a flat file that I&#8217;ve been working on.<br \/>\nFor example, we recently broke words into sounds and needed to add them back to the database.<br \/>\nThe words look like this in the BBEdit file:<\/p>\n<p>a \u2022 l o t<br \/>\n&#8216;a \u2022 c re<br \/>\nai m s<\/p>\n<p>The easies way that I&#8217;ve found to bring the sounds into the larger table is to first create a new table with id and sounds as the fields, import the sounds data, and then merge the two tables. Note: This is how it works with PHP MyAdmin. It may be slightly different from the command line.<\/p>\n<p>This code imports the data into the Sounds table. Note that it ends with a semi-colon and no comma.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\nINSERT INTO `Sounds` (`id`, `sounds`) VALUES\n(1, &#039;a \u2022 l o t&#039;),\n(2, &#039;a \u2022 c re&#039;),\n(3, &#039;a f \u2022 t er&#039;),\n(4, &#039;ai m s&#039;),\n...\n(478, &#039;c o m \u2022 p o s t&#039;);\n<\/code><\/pre><\/p>\n<p>Now I can merge the sounds into another table in the same database by using the UPDATE command. <b>You must include <i>both<\/i> tables after UPDATE, even though you are only updating data in one of the tables<\/b>. Note that when using PHP MyAdmin you need to indicate the fields with the table name in backquotes, a dot, and then the field in backquotes. This may be different in the command line.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\nUPDATE `Pictures`, `Sounds` \nSET `Pictures`.`sounds`=`Sounds`.`sounds` \nWHERE `Pictures`.`id` = `Sounds`.`id`;\n<\/code><\/pre><\/p>\n<p>Here&#8217;s another example.<br \/>\n<pre><code class=\"\u2019smaller\u2019 preserve-code-formatting\">\nUPDATE `Pictures`, `ArticIV_Phonemes`&nbsp;&nbsp;\nSET `Pictures`.`concatenated_phonemes` = `ArticIV_Phonemes`.`Concatenated_phonemes` \nWHERE `Pictures`.`id` = `ArticIV_Phonemes`.`id`\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ll want to add a new field to a table and I have the data in a flat file that I&#8217;ve been working on. For example, we recently broke words into sounds and needed to add them back to the database. The words look like this in the BBEdit file: a \u2022 l o t &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1077\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Things I can&#8217;t remember &#8211; MySQL<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-1077","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1077"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1077\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}