Comments (5)
- レコードを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.
IDが1のレコードのeditorをsatoに更新
既に更新した後のログのように見受けられます。
再度id=1のレコードを追加して、editorを書き換えるようにしてください。
また、Warningが出ている時は、SQLを発行した直後にSHOW WARNINGS;
すると警告の詳細が見られます。今後警告が出た時は合わせて確認すると良いと思います。
from training.
- レコードを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.
確認しました、OKです!
from training.
確認しましたOKですー
from training.
Related Issues (20)
- サーバサイド - フレームワーク - フレームワークとは HOT 3
- サーバサイド - フレームワーク - Laravel - インストールと設定 HOT 3
- サーバサイド - フレームワーク - Laravel - routingとview作成
- サーバサイド - フレームワーク - Laravel - テンプレートエンジンのBladeを使う HOT 2
- サーバサイド - フレームワーク - Laravel - Controller作成 HOT 1
- サーバサイド - フレームワーク - Laravel - フォームのバリデーション、CSRF対策 HOT 2
- フロントエンド - JavaScript/jQuery - JavaScript/jQueryを理解する HOT 3
- フロントエンド - JavaScript/jQuery - Hello World!
- フロントエンド - JavaScript/jQuery - 関数を作る
- フロントエンド - JavaScript/jQuery - DOM操作
- フロントエンド - JavaScript/jQuery - イベント操作
- フロントエンド - JavaScript/jQuery - 条件分岐
- フロントエンド - JavaScript/jQuery - ajax通信
- サーバサイド - サーバサイドテスト - 自動ユニットテストの基礎 HOT 3
- サーバサイド - PHP - PHPを理解する HOT 6
- サーバサイド - PHP - PHPを書く HOT 11
- サーバサイド - PHP - フォーム作成
- フロントエンド - JavaScriptTraining HOT 1
- ruby - 環境構築 HOT 8
- ruby - 基本構文 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from training.