중고 신입이 개발해보기..

MySQL 생활 코딩 따라하기 본문

Database/MySQL

MySQL 생활 코딩 따라하기

rootkaien 2018. 4. 19. 11:43



생활 코딩 DATABASE MySQL 강의를 보면서.. 실습한것. 


설치하는 부분은 패스 



> SHOW DATABASES;


/<------------------------------------>/


- 생성

mysql> CREATE DATABASE opentutorial;

Query OK, 1 row affected (0.00 sec)


- 삭제

mysql> drop DATABASE opentutorial;

Query OK, 0 rows affected (0.01 sec)


/<------------------------------------>/


table, 표

- 수평으로 보면 row, record, 행

- 수직으로 보면 column, 컬럼, 열 - 데이터 타입, 구조


/<------------------------------------>/


CREATE TABLE topc(

  id INT(11) NOT NULL AUTO_INCREMENT,

  title VARCHAR(100) NOT NULL,

  description TEXT NULL,

  created DATETIME NOT NULL,

  author VARCHAR(15) NULL,

  profile VARCHAR(200) NULL,

  PRIMARY KEY(id)

  );


/<------------------------------------>/



NOT NULL -> 공백을 허용하지 않는다.

AUTO_INCREMENT -> 주로 id 처럼 중복되지 안되는 퀄럼을 자동으로 증가하도록 옵셥을 추가

VARCHAR(100) -> string type, 최대 255문자, (100) 100자 한정으로 지정

TEXT -> 65,535자의 글자를 허용한다.

PRIMARY KEY(id) -> id값은 중복되면안된다는 뜻.. 일단은..


mysql> CREATE TABLE topc(

    ->   id INT(11) NOT NULL AUTO_INCREMENT,

    ->   title VARCHAR(100) NOT NULL,

    ->   description TEXT NULL,

    ->   created DATETIME NOT NULL,

    ->   author VARCHAR(15) NULL,

    ->   profile VARCHAR(200) NULL,

    ->   PRIMARY KEY(id)

    ->   );

Query OK, 0 rows affected (0.03 sec)


/<------------------------------------>/



table 이름 변경

// 첨에.. 이름을 잘못 입력해서.. 변경 



mysql> show tables;

+-------------------------+

| Tables_in_opentutorials |

+-------------------------+

| topc                    |

+-------------------------+

1 row in set (0.00 sec)


mysql> rename table topc to topic;

Query OK, 0 rows affected (0.02 sec)


mysql> show tables;

+-------------------------+

| Tables_in_opentutorials |

+-------------------------+

| topic                   |

+-------------------------+

1 row in set (0.00 sec)



/<------------------------------------>/


비빌번호 재 설정

> SET PASSWORD = PASSWORD('my_password');


/<------------------------------------>/


CRUD


- Create

- Read

- Update

- Delete





# CREAET





- 데이터를 추가


- topic의 구조를 보여준다.

INSERT INTO table_name (colum1, column2,....) VALUES (value1, value2..);


mysql> DESC topic;

+-------------+--------------+------+-----+---------+----------------+

| Field       | Type         | Null | Key | Default | Extra          |

+-------------+--------------+------+-----+---------+----------------+

| id          | int(11)      | NO   | PRI | NULL    | auto_increment |

| title       | varchar(100) | NO   |     | NULL    |                |

| description | text         | YES  |     | NULL    |                |

| created     | datetime     | NO   |     | NULL    |                |

| author      | varchar(15)  | YES  |     | NULL    |                |

| profile     | varchar(200) | YES  |     | NULL    |                |

+-------------+--------------+------+-----+---------+----------------+

6 rows in set (0.02 sec)




mysql> INSERT INTO topic (title, description, created, author, profile ) VALUES("MySQL", "Hello MySQL~:) ", NOW(), 'egoing', 'developer');

Query OK, 1 row affected (0.01 sec)





# READ





mysql> SELECT * FROM topic;

+----+-------+-----------------+---------------------+--------+-----------+

| id | title | description     | created             | author | profile   |

+----+-------+-----------------+---------------------+--------+-----------+

|  1 | MySQL | Hello MySQL~:)  | 2018-04-13 16:13:53 | egoing | developer |

+----+-------+-----------------+---------------------+--------+-----------+

1 row in set (0.00 sec)


mysql> INSERT INTO topic (title, description, created, author, profile ) VALUES("ORACLE", "Hello oracle~:) ", NOW(), 'egoing', 'developer');

Query OK, 1 row affected (0.00 sec)


mysql> SELECT * FROM topic;                                                                                                            +----+--------+------------------+---------------------+--------+-----------+

| id | title  | description      | created             | author | profile   |

+----+--------+------------------+---------------------+--------+-----------+

|  1 | MySQL  | Hello MySQL~:)   | 2018-04-13 16:13:53 | egoing | developer |

|  2 | ORACLE | Hello oracle~:)  | 2018-04-13 16:15:57 | egoing | developer |

+----+--------+------------------+---------------------+--------+-----------+

2 rows in set (0.00 sec)


mysql> INSERT INTO topic (title, description, created, author, profile ) VALUES("SQL Server", "SQL Server is... ", NOW(), 'egoing', 'developer');

Query OK, 1 row affected (0.01 sec)


mysql>

mysql>

mysql> INSERT INTO topic (title, description, created, author, profile ) VALUES("PostgreSQL", "PostgreSQL is... ", NOW(), 'egoing', 'developer');

Query OK, 1 row affected (0.00 sec)


mysql>

mysql> INSERT INTO topic (title, description, created, author, profile ) VALUES("MongoDB", "MongoDB is... ", NOW(), 'egoing', 'developer');

Query OK, 1 row affected (0.00 sec)


mysql> SELECT * FROM topic;                                                                                                            

+----+------------+-------------------+---------------------+--------+-----------+

| id | title      | description       | created             | author | profile   |

+----+------------+-------------------+---------------------+--------+-----------+

|  1 | MySQL      | Hello MySQL~:)    | 2018-04-13 16:13:53 | egoing | developer |

|  2 | ORACLE     | Hello oracle~:)   | 2018-04-13 16:15:57 | egoing | developer |

|  3 | SQL Server | SQL Server is...  | 2018-04-13 16:18:01 | egoing | developer |

|  4 | PostgreSQL | PostgreSQL is...  | 2018-04-13 16:18:01 | egoing | developer |

|  5 | MongoDB    | MongoDB is...     | 2018-04-13 16:18:02 | egoing | developer |

+----+------------+-------------------+---------------------+--------+-----------+

5 rows in set (0.00 sec)

// 해당 테이블의 모든 테이블을 볼수 있다.


mysql>


mysql> SELECT id, title, created, author FROM topic;

+----+------------+---------------------+--------+

| id | title      | created             | author |

+----+------------+---------------------+--------+

|  1 | MySQL      | 2018-04-13 16:13:53 | egoing |

|  2 | ORACLE     | 2018-04-13 16:15:57 | egoing |

|  3 | SQL Server | 2018-04-13 16:18:01 | egoing |

|  4 | PostgreSQL | 2018-04-13 16:18:01 | egoing |

|  5 | MongoDB    | 2018-04-13 16:18:02 | egoing |

+----+------------+---------------------+--------+

5 rows in set (0.00 sec)


// 적혀있는 컬럼만 출력된다.



// 공식 메뉴얼

SELECT

    [ALL | DISTINCT | DISTINCTROW ] // []대괄호로 이쓴ㄴ 부분은 생략이 가능한다.

      [HIGH_PRIORITY]

      [STRAIGHT_JOIN]

      [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]

      [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]

    select_expr [, select_expr ...]   // 익스프레션.

    [FROM table_references              // form 은 생략가능하다.

      [PARTITION partition_list]

    [WHERE where_condition]             // where은 form 뒤에 온다.

    [GROUP BY {col_name | expr | position}

      [ASC | DESC], ... [WITH ROLLUP]]

    [HAVING where_condition]

    [ORDER BY {col_name | expr | position}

      [ASC | DESC], ...]

    [LIMIT {[offset,] row_count | row_count OFFSET offset}]

    [PROCEDURE procedure_name(argument_list)]

    [INTO OUTFILE 'file_name'

        [CHARACTER SET charset_name]

        export_options

      | INTO DUMPFILE 'file_name'

      | INTO var_name [, var_name]]

    [FOR UPDATE | LOCK IN SHARE MODE]]



mysql> SELECT id, title, created, author FROM topic WHERE author='egoing';

+----+------------+---------------------+--------+

| id | title      | created             | author |

+----+------------+---------------------+--------+

|  1 | MySQL      | 2018-04-13 16:13:53 | egoing |

|  2 | ORACLE     | 2018-04-13 16:15:57 | egoing |

|  3 | SQL Server | 2018-04-13 16:18:01 | egoing |

|  4 | PostgreSQL | 2018-04-13 16:18:01 | egoing |

|  5 | MongoDB    | 2018-04-13 16:18:02 | egoing |

+----+------------+---------------------+--------+

5 rows in set (0.01 sec)

// egoing만 찾아준다.


mysql> SELECT id, title, created, author FROM topic WHERE author='egoing' ORDER BY id DESC;

+----+------------+---------------------+--------+

| id | title      | created             | author |

+----+------------+---------------------+--------+

|  5 | MongoDB    | 2018-04-13 16:18:02 | egoing |

|  4 | PostgreSQL | 2018-04-13 16:18:01 | egoing |

|  3 | SQL Server | 2018-04-13 16:18:01 | egoing |

|  2 | ORACLE     | 2018-04-13 16:15:57 | egoing |

|  1 | MySQL      | 2018-04-13 16:13:53 | egoing |

+----+------------+---------------------+--------+

5 rows in set (0.00 sec)


// ORDER BY 은 정령방식은데 DESC 는 큰숫다.. 그래서 아이디 역순으로 나온다


mysql> SELECT id, title, created, author FROM topic WHERE author='egoing' ORDER BY id DESC LIMIT 2;

+----+------------+---------------------+--------+

| id | title      | created             | author |

+----+------------+---------------------+--------+

|  5 | MongoDB    | 2018-04-13 16:18:02 | egoing |

|  4 | PostgreSQL | 2018-04-13 16:18:01 | egoing |

+----+------------+---------------------+--------+

2 rows in set (0.00 sec)


// 리미트 2개만 불러오는.. 뒤에서 부터






#  Update




mysql> SELECT * FROM topic;

+----+------------+-------------------+---------------------+--------+-----------+

| id | title      | description       | created             | author | profile   |

+----+------------+-------------------+---------------------+--------+-----------+

|  1 | MySQL      | Hello MySQL~:)    | 2018-04-13 16:13:53 | egoing | developer |

|  2 | ORACLE     | Hello oracle~:)   | 2018-04-13 16:15:57 | egoing | developer |

|  3 | SQL Server | SQL Server is...  | 2018-04-13 16:18:01 | egoing | developer |

|  4 | PostgreSQL | PostgreSQL is...  | 2018-04-13 16:18:01 | egoing | developer |

|  5 | MongoDB    | MongoDB is...     | 2018-04-13 16:18:02 | egoing | developer |

+----+------------+-------------------+---------------------+--------+-----------+

5 rows in set (0.00 sec)


mysql> UPDATE topic SET author='duru', profile='data administrator' WHERE id=3;

Query OK, 1 row affected (0.02 sec)

Rows matched: 1  Changed: 1  Warnings: 0


mysql> SELECT * FROM topic;

+----+------------+-------------------+---------------------+--------+--------------------+

| id | title      | description       | created             | author | profile            |

+----+------------+-------------------+---------------------+--------+--------------------+

|  1 | MySQL      | Hello MySQL~:)    | 2018-04-13 16:13:53 | egoing | developer          |

|  2 | ORACLE     | Hello oracle~:)   | 2018-04-13 16:15:57 | egoing | developer          |

|  3 | SQL Server | SQL Server is...  | 2018-04-13 16:18:01 | duru   | data administrator |

|  4 | PostgreSQL | PostgreSQL is...  | 2018-04-13 16:18:01 | egoing | developer          |

|  5 | MongoDB    | MongoDB is...     | 2018-04-13 16:18:02 | egoing | developer          |

+----+------------+-------------------+---------------------+--------+--------------------+

5 rows in set (0.00 sec)



// update 할때 where를 안하면.. 모든게 변경되니... 꼭 해야된다. 주의 주의

mysql> UPDATE topic SET author='taeho', profile='data scientist, developer' WHERE id=4;

Query OK, 1 row affected (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 0


mysql> select * from topic;

+----+------------+-------------------+---------------------+--------+---------------------------+

| id | title      | description       | created             | author | profile                   |

+----+------------+-------------------+---------------------+--------+---------------------------+

|  1 | MySQL      | Hello MySQL~:)    | 2018-04-13 16:13:53 | egoing | developer                 |

|  2 | ORACLE     | Hello oracle~:)   | 2018-04-13 16:15:57 | egoing | developer                 |

|  3 | SQL Server | SQL Server is...  | 2018-04-13 16:18:01 | duru   | data administrator        |

|  4 | PostgreSQL | PostgreSQL is...  | 2018-04-13 16:18:01 | taeho  | data scientist, developer |

+----+------------+-------------------+---------------------+--------+---------------------------+

4 rows in set (0.00 sec)



# DELETE


// 요기도. where안하면 다. 날라간다.. 조심 조심..





mysql> SELECT * From topic;

+----+------------+-------------------+---------------------+--------+---------------------------+

| id | title      | description       | created             | author | profile                   |

+----+------------+-------------------+---------------------+--------+---------------------------+

|  1 | MySQL      | Hello MySQL~:)    | 2018-04-13 16:13:53 | egoing | developer                 |

|  2 | ORACLE     | Hello oracle~:)   | 2018-04-13 16:15:57 | egoing | developer                 |

|  3 | SQL Server | SQL Server is...  | 2018-04-13 16:18:01 | duru   | data administrator        |

|  4 | PostgreSQL | PostgreSQL is...  | 2018-04-13 16:18:01 | taeho  | data scientist, developer |

|  5 | MongoDB    | MongoDB is...     | 2018-04-13 16:18:02 | egoing | developer                 |

+----+------------+-------------------+---------------------+--------+---------------------------+

5 rows in set (0.00 sec)


mysql> DELETE FROM topic WHERE id = 5;

Query OK, 1 row affected (0.00 sec)


mysql> SELECT * From topic;

+----+------------+-------------------+---------------------+--------+---------------------------+

| id | title      | description       | created             | author | profile                   |

+----+------------+-------------------+---------------------+--------+---------------------------+

|  1 | MySQL      | Hello MySQL~:)    | 2018-04-13 16:13:53 | egoing | developer                 |

|  2 | ORACLE     | Hello oracle~:)   | 2018-04-13 16:15:57 | egoing | developer                 |

|  3 | SQL Server | SQL Server is...  | 2018-04-13 16:18:01 | duru   | data administrator        |

|  4 | PostgreSQL | PostgreSQL is...  | 2018-04-13 16:18:01 | taeho  | data scientist, developer |

+----+------------+-------------------+---------------------+--------+---------------------------+

4 rows in set (0.00 sec)


// 삭제한거 다시.. 추가함.. 그래서 id가 6이당~~


mysql> INSERT INTO topic (title, description, created, author, profile ) VALUES("MongoDB", "MongoDB is... ", NOW(), 'egoing', 'developer');

Query OK, 1 row affected (0.01 sec)


mysql> SELECT * FROM topic;

+----+------------+-------------------+---------------------+--------+---------------------------+

| id | title      | description       | created             | author | profile                   |

+----+------------+-------------------+---------------------+--------+---------------------------+

|  1 | MySQL      | Hello MySQL~:)    | 2018-04-13 16:13:53 | egoing | developer                 |

|  2 | ORACLE     | Hello oracle~:)   | 2018-04-13 16:15:57 | egoing | developer                 |

|  3 | SQL Server | SQL Server is...  | 2018-04-13 16:18:01 | duru   | data administrator        |

|  4 | PostgreSQL | PostgreSQL is...  | 2018-04-13 16:18:01 | taeho  | data scientist, developer |

|  6 | MongoDB    | MongoDB is...     | 2018-04-13 18:15:05 | egoing | developer                 |

+----+------------+-------------------+---------------------+--------+---------------------------+

5 rows in set (0.00 sec)


mysql>




<--------------------------------- 관계형 데이터 베이스 --------------------------->


Relational DATABASE

; 혁신 innovation

; 본질 essence


관계형 데이터 베이스의 .. 특징은 무엇일까.. ??


- 중복된 테이블을 제거하고... 다른 테이블로 만든다..

- 여기에서 author, profile 이. 중복 되고 있다..


<------------------------------------------------------------>


관계형 데이터베이스의  JOIN 기능을.. 설명~~~


mysql> SHOW TABLES;

+-------------------------+

| Tables_in_opentutorials |

+-------------------------+

| topic                   |

+-------------------------+

1 row in set (0.00 sec)


mysql> RENAME TABLE topic To topic_backup;

Query OK, 0 rows affected (0.01 sec)


mysql> SHOW TABLES;

+-------------------------+

| Tables_in_opentutorials |

+-------------------------+

| topic_backup            |

+-------------------------+

1 row in set (0.00 sec)



<------------------------------------------------------------>



mysql> CREATE TABLE `topic` (

    ->   `id` int(11) NOT NULL AUTO_INCREMENT,

    ->   `title` varchar(30) NOT NULL,

    ->   `description` text,

    ->   `created` datetime NOT NULL,

    ->   `author_id` int(11) DEFAULT NULL,

    ->   PRIMARY KEY (`id`)

    -> );

Query OK, 0 rows affected (0.02 sec)


mysql> DESC topic;

+-------------+-------------+------+-----+---------+----------------+

| Field       | Type        | Null | Key | Default | Extra          |

+-------------+-------------+------+-----+---------+----------------+

| id          | int(11)     | NO   | PRI | NULL    | auto_increment |

| title       | varchar(30) | NO   |     | NULL    |                |

| description | text        | YES  |     | NULL    |                |

| created     | datetime    | NO   |     | NULL    |                |

| author_id   | int(11)     | YES  |     | NULL    |                |

+-------------+-------------+------+-----+---------+----------------+

5 rows in set (0.00 sec)




<------------------------------------------------------------>




mysql> CREATE TABLE `author` (

    ->   `id` int(11) NOT NULL AUTO_INCREMENT,

    ->   `name` varchar(20) NOT NULL,

    ->   `profile` varchar(200) DEFAULT NULL,

    ->   PRIMARY KEY (`id`)

    -> ) ;

Query OK, 0 rows affected (0.01 sec)


mysql> DESC author;

+---------+--------------+------+-----+---------+----------------+

| Field   | Type         | Null | Key | Default | Extra          |

+---------+--------------+------+-----+---------+----------------+

| id      | int(11)      | NO   | PRI | NULL    | auto_increment |

| name    | varchar(20)  | NO   |     | NULL    |                |

| profile | varchar(200) | YES  |     | NULL    |                |

+---------+--------------+------+-----+---------+----------------+

3 rows in set (0.00 sec)




<------------------------------------------------------------>



mysql> INSERT INTO `author` VALUES (1,'egoing','developer');

Query OK, 1 row affected (0.01 sec)


mysql> INSERT INTO `author` VALUES (2,'duru','database administrator');

Query OK, 1 row affected (0.00 sec)


mysql> INSERT INTO `author` VALUES (3,'taeho','data scientist, developer');

Query OK, 1 row affected (0.01 sec)


mysql>

mysql> SELECT * FROM author;

+----+--------+---------------------------+

| id | name   | profile                   |

+----+--------+---------------------------+

|  1 | egoing | developer                 |

|  2 | duru   | database administrator    |

|  3 | taeho  | data scientist, developer |

+----+--------+---------------------------+

3 rows in set (0.00 sec)



<------------------------------------------------------------>


mysql> INSERT INTO `topic` VALUES (1,'MySQL','MySQL is...','2018-01-01 12:10:11',1);

Query OK, 1 row affected (0.00 sec)


mysql> INSERT INTO `topic` VALUES (2,'Oracle','Oracle is ...','2018-01-03 13:01:10',1);

Query OK, 1 row affected (0.00 sec)


mysql> INSERT INTO `topic` VALUES (3,'SQL Server','SQL Server is ...','2018-01-20 11:01:10',2);

Query OK, 1 row affected (0.00 sec)


mysql> INSERT INTO `topic` VALUES (4,'PostgreSQL','PostgreSQL is ...','2018-01-23 01:03:03',3);

Query OK, 1 row affected (0.00 sec)


mysql> INSERT INTO `topic` VALUES (5,'MongoDB','MongoDB is ...','2018-01-30 12:31:03',1);

Query OK, 1 row affected (0.01 sec)



mysql> SELECT * FROM topic;

+----+------------+-------------------+---------------------+-----------+

| id | title      | description       | created             | author_id |

+----+------------+-------------------+---------------------+-----------+

|  1 | MySQL      | MySQL is...       | 2018-01-01 12:10:11 |         1 |

|  2 | Oracle     | Oracle is ...     | 2018-01-03 13:01:10 |         1 |

|  3 | SQL Server | SQL Server is ... | 2018-01-20 11:01:10 |         2 |

|  4 | PostgreSQL | PostgreSQL is ... | 2018-01-23 01:03:03 |         3 |

|  5 | MongoDB    | MongoDB is ...    | 2018-01-30 12:31:03 |         1 |

+----+------------+-------------------+---------------------+-----------+

5 rows in set (0.00 sec)




mysql> INSERT INTO topic(title, description, created, author_id) VALUES ('MariaDB', 'MariaDB is...', NOW(), 2);

Query OK, 1 row affected (0.01 sec)


mysql> SELECT * FROM topic;

+----+------------+-------------------+---------------------+-----------+

| id | title      | description       | created             | author_id |

+----+------------+-------------------+---------------------+-----------+

|  1 | MySQL      | MySQL is...       | 2018-01-01 12:10:11 |         1 |

|  2 | Oracle     | Oracle is ...     | 2018-01-03 13:01:10 |         1 |

|  3 | SQL Server | SQL Server is ... | 2018-01-20 11:01:10 |         2 |

|  4 | PostgreSQL | PostgreSQL is ... | 2018-01-23 01:03:03 |         3 |

|  5 | MongoDB    | MongoDB is ...    | 2018-01-30 12:31:03 |         1 |

|  6 | MariaDB    | MariaDB is...     | 2018-04-13 18:44:54 |         2 |

+----+------------+-------------------+---------------------+-----------+

6 rows in set (0.00 sec)


<------------------------------------------------------------>


관계형 데이터베이스의 조인기능~~

- 하나의 테이블로 있는 것처럼.. 검색한다..


mysql> SELECT * FROM topic LEFT JOIN author ON topic.author_id = author.id;

+----+------------+-------------------+---------------------+-----------+------+--------+---------------------------+

| id | title      | description       | created             | author_id | id   | name   | profile                   |

+----+------------+-------------------+---------------------+-----------+------+--------+---------------------------+

|  1 | MySQL      | MySQL is...       | 2018-01-01 12:10:11 |         1 |    1 | egoing | developer                 |

|  2 | Oracle     | Oracle is ...     | 2018-01-03 13:01:10 |         1 |    1 | egoing | developer                 |

|  5 | MongoDB    | MongoDB is ...    | 2018-01-30 12:31:03 |         1 |    1 | egoing | developer                 |

|  3 | SQL Server | SQL Server is ... | 2018-01-20 11:01:10 |         2 |    2 | duru   | database administrator    |

|  6 | MariaDB    | MariaDB is...     | 2018-04-13 18:44:54 |         2 |    2 | duru   | database administrator    |

|  4 | PostgreSQL | PostgreSQL is ... | 2018-01-23 01:03:03 |         3 |    3 | taeho  | data scientist, developer |

+----+------------+-------------------+---------------------+-----------+------+--------+---------------------------+

6 rows in set (0.01 sec)


mysql> SELECT id, title, description, created, name, profile FROM topic LEFT JOIN author ON topic.author_id = author.id;

ERROR 1052 (23000): Column 'id' in field list is ambiguous // id가 멀 뜻하는데.. mysql입장에선.. 애매하다~~~


mysql> SELECT topic.id, title, description, created, name, profile FROM topic LEFT JOIN author ON topic.author_id = author.id;

+----+------------+-------------------+---------------------+--------+---------------------------+

| id | title      | description       | created             | name   | profile                   |

+----+------------+-------------------+---------------------+--------+---------------------------+

|  1 | MySQL      | MySQL is...       | 2018-01-01 12:10:11 | egoing | developer                 |

|  2 | Oracle     | Oracle is ...     | 2018-01-03 13:01:10 | egoing | developer                 |

|  5 | MongoDB    | MongoDB is ...    | 2018-01-30 12:31:03 | egoing | developer                 |

|  3 | SQL Server | SQL Server is ... | 2018-01-20 11:01:10 | duru   | database administrator    |

|  6 | MariaDB    | MariaDB is...     | 2018-04-13 18:44:54 | duru   | database administrator    |

|  4 | PostgreSQL | PostgreSQL is ... | 2018-01-23 01:03:03 | taeho  | data scientist, developer |

+----+------------+-------------------+---------------------+--------+---------------------------+

6 rows in set (0.00 sec)



// 사람이 보기에.. id가. 좀 애매하니깐.. id가. topic id 라고 명시적으로 적어준다.


mysql>  SELECT topic.id AS topic_id, title, description, created, name, profile FROM topic LEFT JOIN author ON topic.author_id = author.id;

+----------+------------+-------------------+---------------------+--------+---------------------------+

| topic_id | title      | description       | created             | name   | profile                   |

+----------+------------+-------------------+---------------------+--------+---------------------------+

|        1 | MySQL      | MySQL is...       | 2018-01-01 12:10:11 | egoing | developer                 |

|        2 | Oracle     | Oracle is ...     | 2018-01-03 13:01:10 | egoing | developer                 |

|        5 | MongoDB    | MongoDB is ...    | 2018-01-30 12:31:03 | egoing | developer                 |

|        3 | SQL Server | SQL Server is ... | 2018-01-20 11:01:10 | duru   | database administrator    |

|        6 | MariaDB    | MariaDB is...     | 2018-04-13 18:44:54 | duru   | database administrator    |

|        4 | PostgreSQL | PostgreSQL is ... | 2018-01-23 01:03:03 | taeho  | data scientist, developer |

+----------+------------+-------------------+---------------------+--------+---------------------------+

6 rows in set (0.00 sec)


https://youtu.be/q0UHWaDRwlk

- 요기까지의 내용~~~~ 

<------------------------------------------------------------>




...



'Database > MySQL' 카테고리의 다른 글

Mac에서 Mysql 완전 삭제 후 재설치  (0) 2021.10.26
Comments