{"id":2639,"date":"2014-05-29T16:58:06","date_gmt":"2014-05-29T07:58:06","guid":{"rendered":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/?p=2639"},"modified":"2014-05-29T21:52:45","modified_gmt":"2014-05-29T12:52:45","slug":"sqlite%e3%81%aeupdate%e3%81%ae%e8%90%bd%e3%81%a8%e3%81%97%e7%a9%b4","status":"publish","type":"post","link":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/2014\/05\/29\/2639\/","title":{"rendered":"SQLite\u306e\u30b5\u30d6\u30af\u30a8\u30ea\u306e\u843d\u3068\u3057\u7a74"},"content":{"rendered":"<p>SQLite 3.6.20\u3067\u306e\u8a71\u3002<\/p>\n<p>\u6b21\u306e\u3088\u3046\u306a\uff12\u3064\u306e\u30c6\u30fc\u30d6\u30ebX,Y\u3092\u7528\u610f\u3057\u3066\u3001X\u306b\u306fname\u3001Y\u306b\u306f\u305d\u308c\u305e\u308c\u306b\u5bfe\u5fdc\u3065\u3051\u3057\u305fyear\u3092\u4fdd\u5b58\u3059\u308b\u3082\u306e\u3068\u3057\u305f\u3002<\/p>\n<div class=\"hl-surround\" ><div class=\"hl-main\"><pre>sqlite&gt; CREATE TABLE X (id INTEGER PRIMARY KEY, name TEXT);\r\nsqlite&gt; INSERT INTO X (name) VALUES ('A');\r\nsqlite&gt; INSERT INTO X (name) VALUES ('B');\r\nsqlite&gt; INSERT INTO X (name) VALUES ('C');\r\nsqlite&gt; INSERT INTO X (name) VALUES ('D');<\/pre><\/div><\/div>\n<div class=\"hl-surround\" ><div class=\"hl-main\"><pre>sqlite&gt; CREATE TABLE Y (id INTEGER PRIMARY KEY, year INTEGER, x_id INTEGER);\r\nsqlite&gt; INSERT INTO Y (year, x_id) VALUES (2010, (SELECT id FROM X WHERE name='A'));\r\nsqlite&gt; INSERT INTO Y (year, x_id) VALUES (2011, (SELECT id FROM X WHERE name='B'));\r\nsqlite&gt; INSERT INTO Y (year, x_id) VALUES (2012, (SELECT id FROM X WHERE name='C'));\r\nsqlite&gt; INSERT INTO Y (year, x_id) VALUES (2013, (SELECT id FROM X WHERE name='D'));<\/pre><\/div><\/div>\n<div class=\"hl-surround\" ><div class=\"hl-main\"><pre>sqlite&gt; SELECT Y.id,Y.year,X.name FROM Y LEFT JOIN X ON Y.x_id=X.id;\r\n1|2010|A\r\n2|2011|B\r\n3|2012|C\r\n4|2013|D<\/pre><\/div><\/div>\n<p>Y\u304b\u3089X\u3092\u53c2\u7167\u3059\u308b\u969b\u306bX\u306eid\u3068\u3057\u3066\u3001x_id\u3068\u3044\u3046\u30ab\u30e9\u30e0\u540d\u306b\u3057\u3066\u3044\u308b\u70b9\u306b\u6ce8\u610f\u3002<\/p>\n<p>\u3067\u3001\u3053\u308c\u3092\u66f4\u65b0\u3059\u308b\u969b\u306b\u307e\u3068\u3081\u3066\u6307\u5b9a\u3057\u3088\u3046\u3068\u3057\u3066 WHERE \u53e5\u3067\u306e IN \u3092\u4f7f\u3063\u3066\u6b63\u3057\u304f\u306f<\/p>\n<div class=\"hl-surround\" style=\"height:16.8px;\"><div class=\"hl-main\"><pre>sqlite&gt; UPDATE Y SET year=2014 WHERE x_id IN (SELECT id FROM X WHERE name IN ('B','C'));<\/pre><\/div><\/div>\n<div class=\"hl-surround\" ><div class=\"hl-main\"><pre>sqlite&gt; SELECT Y.id,Y.year,X.name FROM Y LEFT JOIN X ON Y.x_id=X.id;\r\n1|2010|A\r\n2|2014|B\r\n3|2014|C\r\n4|2013|D<\/pre><\/div><\/div>\n<p>\u3068\u3059\u3079\u304d\u3068\u3053\u308d\u3092\u3001\u3046\u3063\u304b\u308aY\u3067\u306ex_id\u306b\u5f15\u304d\u305a\u3089\u308c\u3066\u3001X\u306e\u30c6\u30fc\u30d6\u30eb\u6307\u5b9a\u6642\u306b\u3082id\u3068\u305b\u305a\u6b21\u306e\u3088\u3046\u306bx_id\u3068\u3084\u3063\u3066\u3057\u307e\u3063\u305f\u3002<\/p>\n<div class=\"hl-surround\" style=\"height:16.8px;\"><div class=\"hl-main\"><pre>sqlite&gt; UPDATE Y SET year=2014 WHERE x_id IN (SELECT x_id FROM X WHERE name in ('B','C'));<\/pre><\/div><\/div>\n<p>\u4e38\u62ec\u5f27\u5185\u306e\u30b5\u30d6\u30af\u30a8\u30ea\u306eSELECT\u3067\u306f\u5b58\u5728\u3057\u306a\u3044\u30ab\u30e9\u30e0\u540d\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u901a\u5e38\u306a\u3089<\/p>\n<div class=\"hl-surround\" ><div class=\"hl-main\"><pre>sqlite&gt; SELECT x_id FROM X WHERE name IN ('B','C');\r\nError: no such column: x_id<\/pre><\/div><\/div>\n<p>\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u306e\u3060\u304c\u3001\u30b5\u30d6\u30af\u30a8\u30ea\u5185\u306b\u3042\u308b\u3068\u3069\u3046\u3082\u30a8\u30e9\u30fc\u306b\u306a\u3089\u305a\u3001\u304b\u3064\u3059\u3079\u3066\u306e\u9805\u76ee\u304c\u5bfe\u8c61\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u3089\u3057\u3044\u3002<\/p>\n<div class=\"hl-surround\" style=\"height:16.8px;\"><div class=\"hl-main\"><pre>sqlite&gt; UPDATE Y SET year=2014 WHERE x_id IN (SELECT x_id FROM X WHERE name in ('B','C'));<\/pre><\/div><\/div>\n<div class=\"hl-surround\" ><div class=\"hl-main\"><pre>sqlite&gt; SELECT Y.id,Y.year,X.name FROM Y LEFT JOIN X ON Y.x_id=X.id;\r\n1|2014|A\r\n2|2014|B\r\n3|2014|C\r\n4|2014|D<\/pre><\/div><\/div>\n<p>\u306a\u3093\u3066\u3053\u3063\u305f\u2026\uff08\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u306a\u3044\u306e\u306f\u3001UPDATE\u306e\u3068\u304d\u3060\u3051\u304b\u3068\u601d\u3063\u305f\u3089\u3001\u4ed6\u306eSELECT\u306a\u3069\u3067\u3082\u540c\u69d8\u306e\u3088\u3046\u3060\uff09\u3002<\/p>\n<p>\u3053\u308c\u306f\u6b63\u3057\u3044\u52d5\u4f5c\u306a\u3093\u3060\u308d\u3046\u304b\uff1f<\/p>\n<p>\u30b5\u30d6\u30af\u30a8\u30ea\u5185\u304c\u7a7a\u306b\u306a\u308b\u304b\u3089\u304b\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u8a66\u3057\u3066\u307f\u305f\u304c\u3001<\/p>\n<div class=\"hl-surround\" style=\"height:16.8px;\"><div class=\"hl-main\"><pre>sqlite&gt; UPDATE Y SET year=2014 WHERE x_id IN ();<\/pre><\/div><\/div>\n<div class=\"hl-surround\" ><div class=\"hl-main\"><pre>sqlite&gt; SELECT Y.id,Y.year,X.name FROM Y left JOIN X ON Y.x_id=X.id;\r\n1|2010|A\r\n2|2011|B\r\n3|2012|C\r\n4|2013|D<\/pre><\/div><\/div>\n<p>\u3053\u306e\u5834\u5408\u306fIN\u306e\u5bfe\u8c61\u306b\u30de\u30c3\u30c1\u3057\u306a\u3044\u3093\u3060\u304b\u3089\u3001\uff08\u5f53\u7136\uff09\u66f4\u65b0\u3055\u308c\u306a\u304b\u3063\u305f\u3002<\/p>\n<p>\u3067\u3001\u3053\u306e\u3068\u304d\u3046\u3063\u304b\u308a\u30b5\u30d6\u30af\u30a8\u30ea\u5185\u306eIN\u306e\u5bfe\u8c61\u3092()\u306b\u3057\u3066\u3057\u307e\u3063\u305f\u304c\u3001<\/p>\n<div class=\"hl-surround\" style=\"height:16.8px;\"><div class=\"hl-main\"><pre>sqlite&gt; UPDATE Y SET year=2014 WHERE x_id IN (SELECT x_id FROM X WHERE name IN ());<\/pre><\/div><\/div>\n<div class=\"hl-surround\" ><div class=\"hl-main\"><pre>sqlite&gt; SELECT Y.id,Y.year,X.name FROM Y LEFT JOIN X ON Y.x_id=X.id;\r\n1|2010|A\r\n2|2011|B\r\n3|2012|C\r\n4|2013|D<\/pre><\/div><\/div>\n<p>\u30ab\u30e9\u30e0\u540d\u3067\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u3044\u3066\u5148\u306e\u4f8b\u304b\u3089\u3059\u308b\u3068\u3059\u3079\u3066\u304c\u66f4\u65b0\u5bfe\u8c61\u306b\u306a\u308a\u305d\u3046\u306a\u306e\u306b\u3001\u3053\u306e\u5834\u5408\u306f\u66f4\u65b0\u3055\u308c\u306a\u304b\u3063\u305f\u3002<\/p>\n<p>\u3088\u304f\u308f\u304b\u3089\u3093\u2026\u3002<\/p>\n<p>SQLite\u306e\u6700\u65b0\u7248\u306f3.8.4.3\u3089\u3057\u3044\u304c\u3001\u305d\u3061\u3089\u3067\u306f\u52d5\u4f5c\u304c\u5909\u308f\u3063\u3066\u3044\u308b\u306e\u304b\u306a\uff1f<\/p>\n<p>[\u8ffd\u8a18]<br \/>\nIN\u306b\u9650\u3089\u305a\u3001=\u3067\u3082\u540c\u69d8\u306b\u30a8\u30e9\u30fc\u6642\u306b\u3059\u3079\u3066\u3092\u5bfe\u8c61\u306b\u66f4\u65b0\u3055\u308c\u3066\u3057\u307e\u3063\u305f\u3002<\/p>\n<div class=\"hl-surround\" style=\"height:16.8px;\"><div class=\"hl-main\"><pre>sqlite&gt; UPDATE Y SET year=2014 WHERE x_id=(SELECT x_id FROM X WHERE name='B');<\/pre><\/div><\/div>\n<div class=\"hl-surround\" ><div class=\"hl-main\"><pre>sqlite&gt; SELECT Y.id,Y.year,X.name FROM Y LEFT JOIN X ON Y.x_id=X.id;\r\n1|2014|A\r\n2|2014|B\r\n3|2014|C\r\n4|2014|D<\/pre><\/div><\/div>\n<p>[\u8ffd\u8a18]<br \/>\n\u5f53\u521d\u3001\u30bf\u30a4\u30c8\u30eb\u3092\u300cupdate\u306e\u843d\u3068\u3057\u7a74\u300d\u3068\u3057\u3066\u3044\u307e\u3057\u305f\u304cupdate\u6642\u306b\u9650\u3089\u306a\u3044\u3088\u3046\u306a\u306e\u3067\u3001\u5f53\u9762\u306e\u539f\u56e0\u3063\u307d\u3044\u300c\u30b5\u30d6\u30af\u30a8\u30ea\u306e\u843d\u3068\u3057\u7a74\u300d\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQLite 3.6.20\u3067\u306e\u8a71\u3002 \u6b21\u306e\u3088\u3046\u306a\uff12\u3064\u306e\u30c6\u30fc\u30d6\u30ebX,Y\u3092\u7528\u610f\u3057\u3066\u3001X\u306b\u306fname\u3001Y\u306b\u306f\u305d\u308c\u305e\u308c\u306b\u5bfe\u5fdc\u3065\u3051\u3057\u305fyear\u3092\u4fdd\u5b58\u3059\u308b\u3082\u306e\u3068\u3057\u305f\u3002 sqlite&gt; CREATE TABLE X (id INT [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[123],"_links":{"self":[{"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/posts\/2639"}],"collection":[{"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/comments?post=2639"}],"version-history":[{"count":8,"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/posts\/2639\/revisions"}],"predecessor-version":[{"id":2647,"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/posts\/2639\/revisions\/2647"}],"wp:attachment":[{"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/media?parent=2639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/categories?post=2639"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mechsys.tec.u-ryukyu.ac.jp\/~oshiro\/SiteList\/wp-json\/wp\/v2\/tags?post=2639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}