Git Product home page Git Product logo

Comments (5)

thori0908 avatar thori0908 commented on August 11, 2024
  • レコードを1件挿入
mysql> insert into kadai1 (id, created_at) values (1,  20150307);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  1 |       | NULL   | 2015-03-07 00:00:00 |
+----+-------+--------+---------------------+
1 row in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/insert/index1.html

  • レコードを複数挿入(SQLは1文のみ)
mysql> insert into kadai1 (id, created_at) values 
    -> (2, 20150308),
    -> (3, 20150309),
    -> (4, 20150310);
Query OK, 3 rows affected, 1 warning (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 1

mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  1 |       | NULL   | 2015-03-07 00:00:00 |
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  4 |       | NULL   | 2015-03-10 00:00:00 |
+----+-------+--------+---------------------+
4 rows in set (0.00 sec)

Ref.
http://www.programming-magic.com/20071221012645/

  • レコードを全件抽出
mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  1 |       | NULL   | 2015-03-07 00:00:00 |
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  4 |       | NULL   | 2015-03-10 00:00:00 |
+----+-------+--------+---------------------+
4 rows in set (0.00 sec)
  • IDが2のレコードを抽出
mysql> select * from kadai1 where id=2;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  2 |       | NULL   | 2015-03-08 00:00:00 |
+----+-------+--------+---------------------+
1 row in set (0.00 sec)
  • created_atを降順に並び替えてレコードを全件取得
mysql> select * from kadai1 order by created_at desc;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  4 |       | NULL   | 2015-03-10 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  1 |       | NULL   | 2015-03-07 00:00:00 |
+----+-------+--------+---------------------+
4 rows in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/select/index11.html

  • IDを降順に並び替えてレコードを2件取得
mysql> select * from kadai1 order by id desc limit 2;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  4 |       | NULL   | 2015-03-10 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
+----+-------+--------+---------------------+
2 rows in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/select/index12.html

  • レコードの総数を抽出
mysql> select count(*) from kadai1;
+----------+
| count(*) |
+----------+
|        4 |
+----------+
1 row in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/function/index6.html

  • 課題4で作成したテーブルを内部結合して全件取得
mysql>  insert into kadai4 (id) values 
    -> (2),
    -> (3),
    -> (4);
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from kadai4;
+----+--------+
| id | detail |
+----+--------+
|  2 | NULL   |
|  3 | NULL   |
|  4 | NULL   |
+----+--------+
3 rows in set (0.00 sec)

mysql> select * from kadai1 inner join kadai4 on kadai1.id=kadai4.id;
+----+-------+--------+---------------------+----+--------+
| id | title | editor | created_at          | id | detail |
+----+-------+--------+---------------------+----+--------+
|  2 |       | NULL   | 2015-03-08 00:00:00 |  2 | NULL   |
|  3 |       | NULL   | 2015-03-09 00:00:00 |  3 | NULL   |
|  4 |       | NULL   | 2015-03-10 00:00:00 |  4 | NULL   |
+----+-------+--------+---------------------+----+--------+
3 rows in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/select/index14.html

  • IDが1のレコードのeditorをsatoに更新
mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  1 |       | sato   | 2015-03-07 00:00:00 |
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  4 |       | NULL   | 2015-03-10 00:00:00 |
+----+-------+--------+---------------------+
4 rows in set (0.00 sec)

mysql> update kadai1 set editor=NULL where id=4;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Ref.
http://www.dbonline.jp/mysql/select/index3.html

  • editorがsatoのレコードを削除
mysql> delete from kadai1 where editor='sato';
Query OK, 1 row affected (0.01 sec)

mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  4 |       | NULL   | 2015-03-10 00:00:00 |
+----+-------+--------+---------------------+
3 rows in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/insert/index10.html

from training.

fr-itaya avatar fr-itaya commented on August 11, 2024
IDが1のレコードのeditorをsatoに更新

既に更新した後のログのように見受けられます。
再度id=1のレコードを追加して、editorを書き換えるようにしてください。

また、Warningが出ている時は、SQLを発行した直後にSHOW WARNINGS;すると警告の詳細が見られます。今後警告が出た時は合わせて確認すると良いと思います。

from training.

thori0908 avatar thori0908 commented on August 11, 2024
  • レコードを1件挿入
mysql> insert into kadai1 (id, created_at) values (1,  20150307);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  1 |       | NULL   | 2015-03-07 00:00:00 |
+----+-------+--------+---------------------+
1 row in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/insert/index1.html

  • レコードを複数挿入(SQLは1文のみ)
mysql> insert into kadai1 (id, created_at) values 
    -> (2, 20150308),
    -> (3, 20150309),
    -> (4, 20150310);
Query OK, 3 rows affected, 1 warning (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 1

mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  1 |       | NULL   | 2015-03-07 00:00:00 |
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  4 |       | NULL   | 2015-03-10 00:00:00 |
+----+-------+--------+---------------------+
4 rows in set (0.00 sec)

Ref.
http://www.programming-magic.com/20071221012645/

  • レコードを全件抽出
mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  1 |       | NULL   | 2015-03-07 00:00:00 |
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  4 |       | NULL   | 2015-03-10 00:00:00 |
+----+-------+--------+---------------------+
4 rows in set (0.00 sec)
  • IDが2のレコードを抽出
mysql> select * from kadai1 where id=2;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  2 |       | NULL   | 2015-03-08 00:00:00 |
+----+-------+--------+---------------------+
1 row in set (0.00 sec)
  • created_atを降順に並び替えてレコードを全件取得
mysql> select * from kadai1 order by created_at desc;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  4 |       | NULL   | 2015-03-10 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  1 |       | NULL   | 2015-03-07 00:00:00 |
+----+-------+--------+---------------------+
4 rows in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/select/index11.html

  • IDを降順に並び替えてレコードを2件取得
mysql> select * from kadai1 order by id desc limit 2;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  4 |       | NULL   | 2015-03-10 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
+----+-------+--------+---------------------+
2 rows in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/select/index12.html

  • レコードの総数を抽出
mysql> select count(*) from kadai1;
+----------+
| count(*) |
+----------+
|        4 |
+----------+
1 row in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/function/index6.html

  • 課題4で作成したテーブルを内部結合して全件取得
mysql>  insert into kadai4 (id) values 
    -> (2),
    -> (3),
    -> (4);
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from kadai4;
+----+--------+
| id | detail |
+----+--------+
|  2 | NULL   |
|  3 | NULL   |
|  4 | NULL   |
+----+--------+
3 rows in set (0.00 sec)

mysql> select * from kadai1 inner join kadai4 on kadai1.id=kadai4.id;
+----+-------+--------+---------------------+----+--------+
| id | title | editor | created_at          | id | detail |
+----+-------+--------+---------------------+----+--------+
|  2 |       | NULL   | 2015-03-08 00:00:00 |  2 | NULL   |
|  3 |       | NULL   | 2015-03-09 00:00:00 |  3 | NULL   |
|  4 |       | NULL   | 2015-03-10 00:00:00 |  4 | NULL   |
+----+-------+--------+---------------------+----+--------+
3 rows in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/select/index14.html

  • IDが1のレコードのeditorをsatoに更新
mysql> update kadai1 set editor='sato' where id=1; 
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  1 |       | sato   | 2015-03-07 00:00:00 |
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  4 |       | NULL   | 2015-03-10 00:00:00 |
+----+-------+--------+---------------------+
4 rows in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/insert/index7.html

  • editorがsatoのレコードを削除
mysql> delete from kadai1 where editor='sato';
Query OK, 1 row affected (0.01 sec)

mysql> select * from kadai1;
+----+-------+--------+---------------------+
| id | title | editor | created_at          |
+----+-------+--------+---------------------+
|  2 |       | NULL   | 2015-03-08 00:00:00 |
|  3 |       | NULL   | 2015-03-09 00:00:00 |
|  4 |       | NULL   | 2015-03-10 00:00:00 |
+----+-------+--------+---------------------+
3 rows in set (0.00 sec)

Ref.
http://www.dbonline.jp/mysql/insert/index10.html

from training.

fr-itaya avatar fr-itaya commented on August 11, 2024

確認しました、OKです!

from training.

fr-matsuo avatar fr-matsuo commented on August 11, 2024

確認しましたOKですー

from training.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.