cmd 창 깨끗히 할 때 : system clear
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database zerobase default character set utf8mb4;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
| mysql |
| performance_schema |
| sakila |
| sys |
| testdb |
| world |
| zerobase |
+--------------------+
9 rows in set (0.00 sec)
mysql> drop database mydb;
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| testdb |
| world |
| zerobase |
+--------------------+
8 rows in set (0.00 sec)
mysql> select host, user from user;
ERROR 1046 (3D000): No database selected
mysql> create table mytable(
-> ^C
mysql> create table mytable
-> (
-> id int,
-> name varchar(16)
-> );
ERROR 1046 (3D000): No database selected
mysql> use zerobase;
Database changed
mysql> create table mytable
-> (
-> id int,
-> name varchar(16)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| mytable |
+--------------------+
1 row in set (0.01 sec)
mysql> desc mytable;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> create table animal
-> (
-> name varchar(16),
-> type varchar(16),
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 5
mysql> create table animal
-> (
-> id int,
-> name varchar(16),
-> type varchar(16)
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| animal |
| mytable |
+--------------------+
2 rows in set (0.00 sec)
mysql> desc animal;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| type | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| testdb |
| world |
| zerobase |
+--------------------+
8 rows in set (0.00 sec)
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| animal |
| mytable |
+--------------------+
2 rows in set (0.00 sec)
mysql> alter table mytable rename person;
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| animal |
| person |
+--------------------+
2 rows in set (0.00 sec)
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| animal |
| person |
+--------------------+
2 rows in set (0.00 sec)
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> alter table person add column agee double;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc person
-> ^C
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| agee | double | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> alter table person modify column agee int;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| agee | int | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> alter table person change column agee age int;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| age | int | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> alter table person drop column age;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> drop table animal;
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| person |
+--------------------+
1 row in set (0.00 sec)
mysql> use testdb;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table
-> (
-> id int,
-> name varchar(16),
-> type varchar(16),
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(
id int,
name varchar(16),
type varchar(16),
)' at line 2
mysql> use testdb;
Database changed
mysql> use testdb;
Database changed
mysql> create table
-> (
-> id int,
-> name varchar(16),
-> type varchar(16),
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(
id int,
name varchar(16),
type varchar(16),
)' at line 2
mysql> create table
-> (
-> id int,
-> name varchar(16),
-> type varchar(16)
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(
id int,
name varchar(16),
type varchar(16)
)' at line 2
mysql> create table animal
-> (
-> id int,
-> name varchar(16),
-> type varchar(16)
-> );
Query OK, 0 rows affected (0.06 sec)
mysql> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| animal |
+------------------+
1 row in set (0.00 sec)
mysql> desc animal;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| type | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> alter table add column agee double;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'add column agee double' at line 1
mysql> alter table animal add column agee double;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc animal;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| type | varchar(16) | YES | | NULL | |
| agee | double | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> alter table animal change column agee age int;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc animal;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| type | varchar(16) | YES | | NULL | |
| age | int | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> alter table animal add column old int;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc animal;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| type | varchar(16) | YES | | NULL | |
| age | int | YES | | NULL | |
| old | int | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> alter table animal drop column age;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc animal;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| type | varchar(16) | YES | | NULL | |
| old | int | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> alter table animal column old sex char;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'column old sex char' at line 1
mysql> alter table animal change column old sex char;
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc animal;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| type | varchar(16) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> drop table animal;
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
Empty set (0.00 sec)
Enter password: ****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases
-> ^C
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| testdb |
| world |
| zerobase |
+--------------------+
8 rows in set (0.01 sec)
mysql> use zerobase;
Database changed
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| person |
+--------------------+
1 row in set (0.01 sec)
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> drop table person;
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
Empty set (0.00 sec)
mysql> create table person
-> (
-> id int,
-> name varchar(16),
-> age int,
-> sex CHAR
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| person |
+--------------------+
1 row in set (0.00 sec)
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| age | int | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> insert into person(id, name, age, sex)
-> values (1, '이효리', 43, 'F');
Query OK, 1 row affected (0.01 sec)
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| age | int | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 43 | F |
+------+-----------+------+------+
1 row in set (0.00 sec)
mysql> insert into person
-> values (2, '이상순', 48, 'M');
Query OK, 1 row affected (0.01 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 43 | F |
| 2 | 이상순 | 48 | M |
+------+-----------+------+------+
2 rows in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| testdb |
| world |
| zerobase |
+--------------------+
8 rows in set (0.00 sec)
mysql> use testdb;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> create table person;
ERROR 4028 (HY000): A table must have at least one visible column.
mysql> create table person
-> (
-> id int,
-> name varchar(16),
-> age int,
-> sex CHAR
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| age | int | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> insert into person
-> values (1, '김지태', 27, 'M');
Query OK, 1 row affected (0.01 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 김지태 | 27 | M |
+------+-----------+------+------+
1 row in set (0.00 sec)
mysql> insert into person
-> values (2, 발레리아, 25, 'F');
ERROR 1054 (42S22): Unknown column '발레리아' in 'field list'
mysql> insert into person
-> values (2, '발레리아, 25, 'F');
'> ^C
mysql> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| person |
+------------------+
1 row in set (0.00 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 김지태 | 27 | M |
+------+-----------+------+------+
1 row in set (0.00 sec)
mysql> insert into person
-> values (2, '발레리아', 26, 'F');
Query OK, 1 row affected (0.01 sec)
mysql> insert into person
-> values (3, '김유태', 25, 'M');
Query OK, 1 row affected (0.01 sec)
mysql> select * from person;
+------+--------------+------+------+
| id | name | age | sex |
+------+--------------+------+------+
| 1 | 김지태 | 27 | M |
| 2 | 발레리아 | 26 | F |
| 3 | 김유태 | 25 | M |
+------+--------------+------+------+
3 rows in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| testdb |
| world |
| zerobase |
+--------------------+
8 rows in set (0.00 sec)
mysql> use zerobase;
Database changed
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| person |
+--------------------+
1 row in set (0.00 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 43 | F |
| 2 | 이상순 | 48 | M |
+------+-----------+------+------+
2 rows in set (0.00 sec)
mysql> insert into person
-> values (3, '유재석', 50, 'M');
Query OK, 1 row affected (0.01 sec)
mysql> insert into person
-> values (4, '이미주', 28, 'F');
Query OK, 1 row affected (0.01 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 43 | F |
| 2 | 이상순 | 48 | M |
| 3 | 유재석 | 50 | M |
| 4 | 이미주 | 28 | F |
+------+-----------+------+------+
4 rows in set (0.00 sec)
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| age | int | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> select name, age. sex from person;
ERROR 1054 (42S22): Unknown column 'age.sex' in 'field list'
mysql> select name, age, sex from person;
+-----------+------+------+
| name | age | sex |
+-----------+------+------+
| 이효리 | 43 | F |
| 이상순 | 48 | M |
| 유재석 | 50 | M |
| 이미주 | 28 | F |
+-----------+------+------+
4 rows in set (0.00 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 43 | F |
| 2 | 이상순 | 48 | M |
| 3 | 유재석 | 50 | M |
| 4 | 이미주 | 28 | F |
+------+-----------+------+------+
4 rows in set (0.00 sec)
mysql> select * from person where sex='F';
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 43 | F |
| 4 | 이미주 | 28 | F |
+------+-----------+------+------+
2 rows in set (0.00 sec)
mysql> use testdb;
Database changed
mysql> use zerobase;
Database changed
mysql> select * from person where age=50;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 3 | 유재석 | 50 | M |
+------+-----------+------+------+
1 row in set (0.00 sec)
mysql> select * from person where sex='F';
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 43 | F |
| 4 | 이미주 | 28 | F |
+------+-----------+------+------+
2 rows in set (0.00 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 43 | F |
| 2 | 이상순 | 48 | M |
| 3 | 유재석 | 50 | M |
| 4 | 이미주 | 28 | F |
+------+-----------+------+------+
4 rows in set (0.00 sec)
mysql> update person set age = 23 where name='이효리';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 23 | F |
| 2 | 이상순 | 48 | M |
| 3 | 유재석 | 50 | M |
| 4 | 이미주 | 28 | F |
+------+-----------+------+------+
4 rows in set (0.00 sec)
mysql> delete from person name = '이상순';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '이상순'' at line 1
mysql> delete from person where name = '이상순';
Query OK, 1 row affected (0.05 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 23 | F |
| 3 | 유재석 | 50 | M |
| 4 | 이미주 | 28 | F |
+------+-----------+------+------+
3 rows in set (0.00 sec)
mysql> update person set sex='F' where name = '유재석';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update person set name='오마주' where name = '이미주';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 23 | F |
| 3 | 유재석 | 50 | F |
| 4 | 오마주 | 28 | F |
+------+-----------+------+------+
3 rows in set (0.00 sec)
mysql> use testdb;
Database changed
mysql> desc person;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
| age | int | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql> desc animal;
ERROR 1146 (42S02): Table 'testdb.animal' doesn't exist
mysql> select * from person;
+------+--------------+------+------+
| id | name | age | sex |
+------+--------------+------+------+
| 1 | 김지태 | 27 | M |
| 2 | 발레리아 | 26 | F |
| 3 | 김유태 | 25 | M |
+------+--------------+------+------+
3 rows in set (0.00 sec)
mysql> delete from person name = '김유태';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '김유태'' at line 1
mysql> delete from person where name='김유테';
Query OK, 0 rows affected (0.00 sec)
mysql> select * from person;
+------+--------------+------+------+
| id | name | age | sex |
+------+--------------+------+------+
| 1 | 김지태 | 27 | M |
| 2 | 발레리아 | 26 | F |
| 3 | 김유태 | 25 | M |
+------+--------------+------+------+
3 rows in set (0.00 sec)
mysql> delete from person where name ='김유태';
Query OK, 1 row affected (0.05 sec)
mysql> select * from person;
+------+--------------+------+------+
| id | name | age | sex |
+------+--------------+------+------+
| 1 | 김지태 | 27 | M |
| 2 | 발레리아 | 26 | F |
+------+--------------+------+------+
2 rows in set (0.00 sec)
mysql> use zerobase;
Database changed
mysql> select * from person;l
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 23 | F |
| 3 | 유재석 | 50 | F |
| 4 | 오마주 | 28 | F |
+------+-----------+------+------+
3 rows in set (0.00 sec)
-> ^C
mysql> update person set sex="M" where name = '유재석';
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 1 | 이효리 | 23 | F |
| 3 | 유재석 | 50 | M |
| 4 | 오마주 | 28 | F |
+------+-----------+------+------+
3 rows in set (0.00 sec)
mysql> delete from person where sex = 'F';
Query OK, 2 rows affected (0.04 sec)
mysql> select * from person;
+------+-----------+------+------+
| id | name | age | sex |
+------+-----------+------+------+
| 3 | 유재석 | 50 | M |
+------+-----------+------+------+
1 row in set (0.00 sec)
mysql> drop table person;
Query OK, 0 rows affected (0.06 sec)
mysql> show tables;
Empty set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| testdb |
| world |
| zerobase |
+--------------------+
8 rows in set (0.00 sec)
mysql> use testdb;
Database changed
mysql> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| person |
+------------------+
1 row in set (0.00 sec)
mysql> drop table person;
Query OK, 0 rows affected (0.05 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| testdb |
| world |
| zerobase |
+--------------------+
8 rows in set (0.00 sec)
mysql> use zerobase;
Database changed
mysql> create table celab;
ERROR 4028 (HY000): A table must have at least one visible column.
mysql> create table celab
-> (
-> id int,
-> ^C
mysql> create table celab
-> (
-> ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> NAME varchar(32) NOT NULL DEFAULT '',
-> BIRTHDAY date,
-> AGE int,
-> SEX char(1),
-> JOB_TITLE varchar(32),
-> AGENCY varchar(32)
-> );
Query OK, 0 rows affected (0.08 sec)
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| celab |
+--------------------+
1 row in set (0.00 sec)
mysql> desc celab;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| ID | int | NO | PRI | NULL | auto_increment |
| NAME | varchar(32) | NO | | | |
| BIRTHDAY | date | YES | | NULL | |
| AGE | int | YES | | NULL | |
| SEX | char(1) | YES | | NULL | |
| JOB_TITLE | varchar(32) | YES | | NULL | |
| AGENCY | varchar(32) | YES | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> select * from celab;
Empty set (0.00 sec)
mysql> insert into celab values (1, '아이유', '1993-05-16', 29, 'F', '가수, 텔런트', 'EDAM엔터테인먼트');
Query OK, 1 row affected (0.04 sec)
mysql> select * from celab;
+----+-----------+------------+------+------+-------------------+------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
+----+-----------+------------+------+------+-------------------+------------------------+
1 row in set (0.00 sec)
mysql> insert into celab values (2, '이미주', '1994-09-23', 28, 'F', '가수', '울림엔터테인먼트');
Query OK, 1 row affected (0.05 sec)
mysql> insert into celab values (3, '송강', '1994-04-23', 28, 'M', '텔런트', '나무엑터스');
Query OK, 1 row affected (0.04 sec)
mysql> insert into celab values (4, '강동원', '1981-01-18', 41, 'M', '영화배우, 텔런트', 'YG엔터테인먼트');
Query OK, 1 row affected (0.05 sec)
mysql> insert into celab values (5, '유재석', '1972-08-14', 50, 'M', 'MC, 개그맨', '안테나');
Query OK, 1 row affected (0.04 sec)
mysql> insert into celab values (6, '차승원', '1970-06-07', 48, 'M', '영화배우, 모델', 'YG엔터테인먼트');
Query OK, 1 row affected (0.05 sec)
mysql> insert into celab values(7, '이수연', '1999-05-03', 23, 'F', '가수', 'YG엔터테인먼트');
Query OK, 1 row affected (0.04 sec)
mysql> select * from celab;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
7 rows in set (0.00 sec)
mysql> select name, age
-> from celab
-> order by age;
+-----------+------+
| name | age |
+-----------+------+
| 이수연 | 23 |
| 이미주 | 28 |
| 송강 | 28 |
| 아이유 | 29 |
| 강동원 | 41 |
| 차승원 | 48 |
| 유재석 | 50 |
+-----------+------+
7 rows in set (0.00 sec)
mysql> select age, name
-> from celab
-> order by age DESC;
+------+-----------+
| age | name |
+------+-----------+
| 50 | 유재석 |
| 48 | 차승원 |
| 41 | 강동원 |
| 29 | 아이유 |
| 28 | 이미주 |
| 28 | 송강 |
| 23 | 이수연 |
+------+-----------+
7 rows in set (0.00 sec)
mysql> select age, name
-> from celab
-> order by age, name;
+------+-----------+
| age | name |
+------+-----------+
| 23 | 이수연 |
| 28 | 송강 |
| 28 | 이미주 |
| 29 | 아이유 |
| 41 | 강동원 |
| 48 | 차승원 |
| 50 | 유재석 |
+------+-----------+
7 rows in set (0.00 sec)
mysql> select age, name
-> from celab
-> order by age DESC, name ASC;
+------+-----------+
| age | name |
+------+-----------+
| 50 | 유재석 |
| 48 | 차승원 |
| 41 | 강동원 |
| 29 | 아이유 |
| 28 | 송강 |
| 28 | 이미주 |
| 23 | 이수연 |
+------+-----------+
7 rows in set (0.00 sec)
mysql> select agency, name
-> drom celab
-> ^C
mysql> select agenct, name
-> from celab
-> order by name ASC;
ERROR 1054 (42S22): Unknown column 'agenct' in 'field list'
mysql> select agency, name
-> from celab
-> order by name;
+--------------------------+-----------+
| agency | name |
+--------------------------+-----------+
| YG엔터테인먼트 | 강동원 |
| 나무엑터스 | 송강 |
| EDAM엔터테인먼트 | 아이유 |
| 안테나 | 유재석 |
| 울림엔터테인먼트 | 이미주 |
| YG엔터테인먼트 | 이수연 |
| YG엔터테인먼트 | 차승원 |
+--------------------------+-----------+
7 rows in set (0.00 sec)
mysql> select name, agency
-> from celab
-> order by name ASC;
+-----------+--------------------------+
| name | agency |
+-----------+--------------------------+
| 강동원 | YG엔터테인먼트 |
| 송강 | 나무엑터스 |
| 아이유 | EDAM엔터테인먼트 |
| 유재석 | 안테나 |
| 이미주 | 울림엔터테인먼트 |
| 이수연 | YG엔터테인먼트 |
| 차승원 | YG엔터테인먼트 |
+-----------+--------------------------+
7 rows in set (0.00 sec)
mysql> select name, birthday, sex, agency
-> from celab
-> order by agency ASC;
+-----------+------------+------+--------------------------+
| name | birthday | sex | agency |
+-----------+------------+------+--------------------------+
| 아이유 | 1993-05-16 | F | EDAM엔터테인먼트 |
| 강동원 | 1981-01-18 | M | YG엔터테인먼트 |
| 차승원 | 1970-06-07 | M | YG엔터테인먼트 |
| 이수연 | 1999-05-03 | F | YG엔터테인먼트 |
| 송강 | 1994-04-23 | M | 나무엑터스 |
| 유재석 | 1972-08-14 | M | 안테나 |
| 이미주 | 1994-09-23 | F | 울림엔터테인먼트 |
+-----------+------------+------+--------------------------+
7 rows in set (0.00 sec)
mysql> select *
-> from celab
-> order by agency, name ASC;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
7 rows in set (0.00 sec)
mysql> select *
-> from celab
-> order by name;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
7 rows in set (0.00 sec)
mysql> select name, age, job_title, agency
-> from celab
-> order by agency ASC, age DESC;
+-----------+------+-------------------------+--------------------------+
| name | age | job_title | agency |
+-----------+------+-------------------------+--------------------------+
| 아이유 | 29 | 가수, 텔런트 | EDAM엔터테인먼트 |
| 차승원 | 48 | 영화배우, 모델 | YG엔터테인먼트 |
| 강동원 | 41 | 영화배우, 텔런트 | YG엔터테인먼트 |
| 이수연 | 23 | 가수 | YG엔터테인먼트 |
| 송강 | 28 | 텔런트 | 나무엑터스 |
| 유재석 | 50 | MC, 개그맨 | 안테나 |
| 이미주 | 28 | 가수 | 울림엔터테인먼트 |
+-----------+------+-------------------------+--------------------------+
7 rows in set (0.00 sec)
mysql> desc celab;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| ID | int | NO | PRI | NULL | auto_increment |
| NAME | varchar(32) | NO | | | |
| BIRTHDAY | date | YES | | NULL | |
| AGE | int | YES | | NULL | |
| SEX | char(1) | YES | | NULL | |
| JOB_TITLE | varchar(32) | YES | | NULL | |
| AGENCY | varchar(32) | YES | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> select * from celab;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
7 rows in set (0.00 sec)
mysql> select name, age
-> from celab
-> where age=29
-> order by age;
+-----------+------+
| name | age |
+-----------+------+
| 아이유 | 29 |
+-----------+------+
1 row in set (0.00 sec)
mysql> select name, age, sex
-> from celab
-> where age != 29
-> order by age DESC;
+-----------+------+------+
| name | age | sex |
+-----------+------+------+
| 유재석 | 50 | M |
| 차승원 | 48 | M |
| 강동원 | 41 | M |
| 이미주 | 28 | F |
| 송강 | 28 | M |
| 이수연 | 23 | F |
+-----------+------+------+
6 rows in set (0.00 sec)
mysql> select name, age
-> from celab
-> where age > 29
-> order by age ASC;
+-----------+------+
| name | age |
+-----------+------+
| 강동원 | 41 |
| 차승원 | 48 |
| 유재석 | 50 |
+-----------+------+
3 rows in set (0.00 sec)
mysql> select name, age
-> from celab
-> where age < 29
-> order by age DESC:
-> ^C
mysql> select name, age
-> from celab
-> where age < 29
-> order by age DESC;
+-----------+------+
| name | age |
+-----------+------+
| 이미주 | 28 |
| 송강 | 28 |
| 이수연 | 23 |
+-----------+------+
3 rows in set (0.00 sec)
mysql> select name, age
-> from celab
-> where age>=29
-> order by ageDESC;
ERROR 1054 (42S22): Unknown column 'ageDESC' in 'order clause'
mysql> select name, age
-> from celab
-> where age >= 29
-> order by age DESC;
+-----------+------+
| name | age |
+-----------+------+
| 유재석 | 50 |
| 차승원 | 48 |
| 강동원 | 41 |
| 아이유 | 29 |
+-----------+------+
4 rows in set (0.00 sec)
mysql> select name, age, agency
-> from celab
-> where age <=29
-> order by age ;
+-----------+------+--------------------------+
| name | age | agency |
+-----------+------+--------------------------+
| 이수연 | 23 | YG엔터테인먼트 |
| 이미주 | 28 | 울림엔터테인먼트 |
| 송강 | 28 | 나무엑터스 |
| 아이유 | 29 | EDAM엔터테인먼트 |
+-----------+------+--------------------------+
4 rows in set (0.00 sec)
mysql> select name, age, agency, job_title, birthday
-> from celab
-> where age <>29
-> order by age ASC;
+-----------+------+--------------------------+-------------------------+------------+
| name | age | agency | job_title | birthday |
+-----------+------+--------------------------+-------------------------+------------+
| 이수연 | 23 | YG엔터테인먼트 | 가수 | 1999-05-03 |
| 이미주 | 28 | 울림엔터테인먼트 | 가수 | 1994-09-23 |
| 송강 | 28 | 나무엑터스 | 텔런트 | 1994-04-23 |
| 강동원 | 41 | YG엔터테인먼트 | 영화배우, 텔런트 | 1981-01-18 |
| 차승원 | 48 | YG엔터테인먼트 | 영화배우, 모델 | 1970-06-07 |
| 유재석 | 50 | 안테나 | MC, 개그맨 | 1972-08-14 |
+-----------+------+--------------------------+-------------------------+------------+
6 rows in set (0.00 sec)
mysql> select age, name from celab where age<=30 order by age ASC;
+------+-----------+
| age | name |
+------+-----------+
| 23 | 이수연 |
| 28 | 이미주 |
| 28 | 송강 |
| 29 | 아이유 |
+------+-----------+
4 rows in set (0.00 sec)
mysql> select age, sex, job_title, agency
-> from celab
-> where name='아이유'
-> order by age;
+------+------+-------------------+------------------------+
| age | sex | job_title | agency |
+------+------+-------------------+------------------------+
| 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
+------+------+-------------------+------------------------+
1 row in set (0.00 sec)
mysql> select name, job_title, agency
-> from celab
-> where agency!='YG엔터테인먼트'
-> order by agency;
+-----------+-------------------+--------------------------+
| name | job_title | agency |
+-----------+-------------------+--------------------------+
| 아이유 | 가수, 텔런트 | EDAM엔터테인먼트 |
| 송강 | 텔런트 | 나무엑터스 |
| 유재석 | MC, 개그맨 | 안테나 |
| 이미주 | 가수 | 울림엔터테인먼트 |
+-----------+-------------------+--------------------------+
4 rows in set (0.00 sec)
mysql> select name, sex, agency
-> from celab
-> where sex='M'
-> order by age DESC, agency ;
+-----------+------+----------------------+
| name | sex | agency |
+-----------+------+----------------------+
| 유재석 | M | 안테나 |
| 차승원 | M | YG엔터테인먼트 |
| 강동원 | M | YG엔터테인먼트 |
| 송강 | M | 나무엑터스 |
+-----------+------+----------------------+
4 rows in set (0.00 sec)
mysql> select sex, agency, name, age
-> from celab
-> where age<=50
-> order by sex ASC;
+------+--------------------------+-----------+------+
| sex | agency | name | age |
+------+--------------------------+-----------+------+
| F | EDAM엔터테인먼트 | 아이유 | 29 |
| F | 울림엔터테인먼트 | 이미주 | 28 |
| F | YG엔터테인먼트 | 이수연 | 23 |
| M | 나무엑터스 | 송강 | 28 |
| M | YG엔터테인먼트 | 강동원 | 41 |
| M | 안테나 | 유재석 | 50 |
| M | YG엔터테인먼트 | 차승원 | 48 |
+------+--------------------------+-----------+------+
7 rows in set (0.00 sec)
mysql> select sex, agency, name, age from celab where age<=50 order by sex ASC, agency DESC;
+------+--------------------------+-----------+------+
| sex | agency | name | age |
+------+--------------------------+-----------+------+
| F | 울림엔터테인먼트 | 이미주 | 28 |
| F | YG엔터테인먼트 | 이수연 | 23 |
| F | EDAM엔터테인먼트 | 아이유 | 29 |
| M | 안테나 | 유재석 | 50 |
| M | 나무엑터스 | 송강 | 28 |
| M | YG엔터테인먼트 | 강동원 | 41 |
| M | YG엔터테인먼트 | 차승원 | 48 |
+------+--------------------------+-----------+------+
7 rows in set (0.00 sec)
mysql> select sex, agency, name, age from celab where age<50 order by sex ASC, agency DESC;
+------+--------------------------+-----------+------+
| sex | agency | name | age |
+------+--------------------------+-----------+------+
| F | 울림엔터테인먼트 | 이미주 | 28 |
| F | YG엔터테인먼트 | 이수연 | 23 |
| F | EDAM엔터테인먼트 | 아이유 | 29 |
| M | 나무엑터스 | 송강 | 28 |
| M | YG엔터테인먼트 | 강동원 | 41 |
| M | YG엔터테인먼트 | 차승원 | 48 |
+------+--------------------------+-----------+------+
6 rows in set (0.00 sec)
mysql> select sex, agency, name, age from celab where age<50 order by sex ASC, agency DESC, name ;
+------+--------------------------+-----------+------+
| sex | agency | name | age |
+------+--------------------------+-----------+------+
| F | 울림엔터테인먼트 | 이미주 | 28 |
| F | YG엔터테인먼트 | 이수연 | 23 |
| F | EDAM엔터테인먼트 | 아이유 | 29 |
| M | 나무엑터스 | 송강 | 28 |
| M | YG엔터테인먼트 | 강동원 | 41 |
| M | YG엔터테인먼트 | 차승원 | 48 |
+------+--------------------------+-----------+------+
6 rows in set (0.00 sec)
mysql> select * from celab;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
7 rows in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| testdb |
| world |
| zerobase |
+--------------------+
8 rows in set (0.00 sec)
mysql> use zerobase
Database changed
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| celab |
+--------------------+
1 row in set (0.00 sec)
mysql> desc celab;
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| ID | int | NO | PRI | NULL | auto_increment |
| NAME | varchar(32) | NO | | | |
| BIRTHDAY | date | YES | | NULL | |
| AGE | int | YES | | NULL | |
| SEX | char(1) | YES | | NULL | |
| JOB_TITLE | varchar(32) | YES | | NULL | |
| AGENCY | varchar(32) | YES | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> select * from celab;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
7 rows in set (0.00 sec)
mysql> select name, age from celab where age=29 sex='F' order by name;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sex='F' order by name' at line 1
mysql> select name, age from celab where age=29, sex='F' order by name;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', sex='F' order by name' at line 1
mysql> select name, age from celab where age=29 sex='F' order by name;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sex='F' order by name' at line 1
mysql> select name age
-> from celab
-> where age=29
-> where sex='F'
-> order by name ASC;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where sex='F'
order by name ASC' at line 4
mysql> select name, age
-> from celab
-> where
-> age=29 and sex='F'
-> order by name;
+-----------+------+
| name | age |
+-----------+------+
| 아이유 | 29 |
+-----------+------+
1 row in set (0.00 sec)
mysql> select * from celab where sex='M' and age>40 order by name DESC;
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
3 rows in set (0.00 sec)
mysql> select from celab where sex='M' and agency='YG엔터테인먼트' oreder by agency ASC;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'oreder by agency ASC' at line 1
mysql> select
-> from celab
-> where sex='M' and AGENCY='YG엔어테인먼트'
-> order by AGENCY;
Empty set (0.00 sec)
mysql> select *
-> from celab
-> where sex='M' and AGENCY='YG엔터테인먼트'
-> order by AGENCY;
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
2 rows in set (0.00 sec)
mysql> select * from celab where age>=30 and sex='M' order by age DESC;
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
3 rows in set (0.00 sec)
mysql> alter table celab rename celeb;
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
+--------------------+
| Tables_in_zerobase |
+--------------------+
| celeb |
+--------------------+
1 row in set (0.00 sec)
mysql> select * from celeb where age<25 OR age>30 order by name;
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
4 rows in set (0.00 sec)
mysql> select * from celeb where age<29 and sex='F' ;
+----+-----------+------------+------+------+-----------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-----------+--------------------------+
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-----------+--------------------------+
2 rows in set (0.00 sec)
mysql> select from celeb where age>30 and sex'M' ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''M'' at line 1
mysql> select from celeb where age>30 and sex='M' ;
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
3 rows in set (0.00 sec)
mysql> select * from celeb where age<29 and sex='F' OR age>30 and sex='M' ;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
5 rows in set (0.00 sec)
mysql> select * from celeb where (age<29 and sex='F') OR (age>30 AND sex='M') order by age, sex;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
5 rows in set (0.00 sec)
mysql> select * from celeb where (agency='나무엑터스' OR agency='YG엔터테인먼트') and (age<30) ;
+----+-----------+------------+------+------+-----------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-----------+----------------------+
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-----------+----------------------+
2 rows in set (0.00 sec)
mysql> select * from celeb where agency='YG엔터테인먼트' OR agency='나무엑터스' AND age<30;
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
4 rows in set (0.00 sec)
mysql> select * from celeb where (agency='YG엔터테인먼트' OR agency='안테나') order by agency ASC;
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
+----+-----------+------------+------+------+-------------------------+----------------------+
4 rows in set (0.00 sec)
mysql> select *
-> from celeb
-> where (agency='YG엔터테인먼트' AND NOT sex='M') OR
-> (job_title='가수' AND NOT agency='YG엔터테인먼트');
+----+-----------+------------+------+------+-----------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-----------+--------------------------+
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-----------+--------------------------+
2 rows in set (0.00 sec)
mysql> select from celeb where (birthday>'1994-00-00' and NOT sex='F') OR (birthday<'1999-00-00' and agency!='안테나');
ERROR 1525 (HY000): Incorrect DATE value: '1994-00-00'
mysql> select from celeb where (birthday>=19900000 and NOT sex='F') OR (birthday=<19790000 and agency!='안테나');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=<19790000 and agency!='안테나')' at line 1
mysql> select *
-> from celeb
-> where (birthday > 19891231 and NOT sex='F') OR
-> (birthday<19790101 and agency!='안테나');
+----+-----------+------------+------+------+----------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+----------------------+----------------------+
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+----------------------+----------------------+
2 rows in set (0.00 sec)
mysql> select * from celeb
-> where NOT agency='YG엔터테인먼트' AND age<=40 order by name ASC;
+----+-----------+------------+------+------+-------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+--------------------------+
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
+----+-----------+------------+------+------+-------------------+--------------------------+
3 rows in set (0.00 sec)
mysql> select * from celeb where NOT sex='M' OR age>=30 order by age DESC;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
6 rows in set (0.00 sec)
mysql> select from celeb
-> where (job
-> ^C
mysql> select from celeb
-> where (NOT job_title='가수' AND sex='F') OR
-> (NOT age<40 AND id%2=1);
+----+-----------+------------+------+------+-------------------+------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
+----+-----------+------------+------+------+-------------------+------------------------+
2 rows in set (0.00 sec)
mysql> select * from celeb
-> where age BETWEEN 20 and 40;
+----+-----------+------------+------+------+-------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------+--------------------------+
4 rows in set (0.00 sec)
mysql> select * from celeb
-> where age>=20 AND age<=40;
+----+-----------+------------+------+------+-------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------+--------------------------+
4 rows in set (0.00 sec)
mysql> select * from celeb where (NOT birthday BETWEEN 19800101 AND 19951231 AND sex='F') OR (agency='YG엔터테인먼트' AND NOT age BETWEEN 20 AND 45);
+----+-----------+------------+------+------+----------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+----------------------+----------------------+
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+----------------------+----------------------+
2 rows in set (0.00 sec)
mysql> select * from celeb where age BETWEEN 30 AND 60 AND sex='M' order by age ASC;
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
+----+-----------+------------+------+------+-------------------------+----------------------+
3 rows in set (0.00 sec)
mysql> select * from celeb where( NOT age BETWEEN 30 AND 60) OR (agency='YG엔터테인먼트') order by age DESC;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
6 rows in set (0.00 sec)
mysql> select * from celeb where id BETWEEN 1 AND 5 AND sex='F' OR (id%2=1) AND sex='M' AND age BETWEEN 20 AND 30;
+----+-----------+------------+------+------+-------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
+----+-----------+------------+------+------+-------------------+--------------------------+
3 rows in set (0.00 sec)
mysql> selece from celeb
-> where NOT agency IN ('나무엑터스', '안테나', '울림엔터테인먼트') AND (sex='F' OR age=>45);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'selece from celeb
where NOT agency IN ('나무엑터스', '안테나', '울림' at line 1
mysql> select from celeb where NOT agency IN ('나무엑터스', '안테나', '울림엔터테인먼트') AND (sex='F' OR age=>45);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=>45)' at line 1
mysql> select from
-> ^C
mysql> select from celeb
-> where NOT agency IN ('나무엑터스', '안테나', '울림엔터테인먼트') AND sex='F' OR age=>45;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=>45' at line 2
mysql> select from celeb where NOT agency IN ('나무엑터스', '안테나', '울림엔터테인먼트') AND sex='F' OR age>=45;
+----+-----------+------------+------+------+----------------------+------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+----------------------+------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+----------------------+------------------------+
4 rows in set (0.00 sec)
mysql> selece from celeb
-> where NOT agency IN ('나무엑터스', '안테나', '울림엔터테인먼트') AND (sex='F' OR age>=45);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'selece from celeb
where NOT agency IN ('나무엑터스', '안테나', '울ë¦' at line 1
mysql> select * from celeb where NOT agency IN ('나무엑터스', '안테나', '울림엔터테인먼트') AND (sex='F' OR age>=45);
+----+-----------+------------+------+------+----------------------+------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+----------------------+------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+----------------------+------------------------+
3 rows in set (0.00 sec)
mysql> select * from celeb
-> where name IN ('아이유', '이미주', '유재석', '송강') AND agency='나무엔터테인먼트';
Empty set (0.00 sec)
mysql> select from celeb wherer name IN ('아이유', '이미주', '유재석', '송강') AND agency='나무엑터스';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name IN ('아이유', '이미주', '유재석', '송강') AND agency='나무엑í' at line 1
mysql> select from celeb where name IN ('아이유', '이미주', '유재석', '송강') AND agency='나무엑터스';
+----+--------+------------+------+------+-----------+-----------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+--------+------------+------+------+-----------+-----------------+
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
+----+--------+------------+------+------+-----------+-----------------+
1 row in set (0.00 sec)
mysql> select * from celeb
-> where agency IN ('안테나', 'YG엔터테인먼트') AND
-> sex='F';
+----+-----------+------------+------+------+-----------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-----------+----------------------+
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-----------+----------------------+
1 row in set (0.00 sec)
mysql> select * from celeb where NOT agency IN ('안테나', 'YG엔터테인먼트') AND sex = 'F';
+----+-----------+------------+------+------+-------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
+----+-----------+------------+------+------+-------------------+--------------------------+
2 rows in set (0.00 sec)
mysql> select * from celeb
-> where name IN ('아이유', '송강', '강동원', '차승원') AND
-> (NOT agency='YG엔터테인먼트') OR age BETWEEN 40 AND 50;
+----+-----------+------------+------+------+-------------------------+------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+------------------------+
5 rows in set (0.00 sec)
mysql> select * from celeb where name IN ('아이유', '송강', '강동원', '차승원') AND (NOT agency='YG엔터테인먼트' OR age BETWEEN 40 AND 50);
+----+-----------+------------+------+------+-------------------------+------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+------------------------+
4 rows in set (0.00 sec)
mysql> select * from celeb;
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
7 rows in set (0.00 sec)
mysql> select * from celeb where agency='YG엔터테인먼트';
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
3 rows in set (0.00 sec)
mysql> select * from celeb where agency LIKE 'YG엔터테인먼트';
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
3 rows in set (0.00 sec)
mysql> select * from celeb where agency LIKE 'YG%';
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
3 rows in set (0.00 sec)
mysql> select * from celeb where agency LIKE '%엔터테인먼트';
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
5 rows in set (0.00 sec)
mysql> select * from celeb where NOT agency LIKE '%엔터테인먼트';
+----+-----------+------------+------+------+---------------+-----------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+---------------+-----------------+
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
+----+-----------+------------+------+------+---------------+-----------------+
2 rows in set (0.00 sec)
mysql> select * from celeb where job_title LIKE '%가수%';
+----+-----------+------------+------+------+-------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------+--------------------------+
3 rows in set (0.00 sec)
mysql> select from celeb where agnecy LIKE '_G%';
ERROR 1054 (42S22): Unknown column 'agnecy' in 'where clause'
mysql> select from celeb where agency LIKE '_G%';
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
3 rows in set (0.00 sec)
mysql> select * from celeb where jobtitle LIKE '가%';
+----+-----------+------------+------+------+-------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------+--------------------------+
3 rows in set (0.00 sec)
mysql> select * from celeb where job_title LIKE '가____%';
+----+-----------+------------+------+------+-------------------+------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------+------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
+----+-----------+------------+------+------+-------------------+------------------------+
1 row in set (0.00 sec)
mysql> select from celeb where job_title '영%모델';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''영%모델'' at line 1
mysql> select from celeb where job_title LIKE '영%모델';
+----+-----------+------------+------+------+----------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+----------------------+----------------------+
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+----------------------+----------------------+
1 row in set (0.00 sec)
mysql> select from celeb where job
-> ^C
mysql> select from celeb where job_title LIKE '영%'OR'텔%';
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
2 rows in set, 1 warning (0.00 sec)
mysql> select * from celeb where job_title LIKE '영%' OR '텔%';
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
2 rows in set, 1 warning (0.00 sec)
mysql> select * from celeb where job_title LIKE '영%' AND '텔%';
Empty set, 1 warning (0.00 sec)
mysql> select * from celeb where job_title LIKE '영%' AND '%텔';
Empty set, 1 warning (0.00 sec)
mysql> select * from celeb where job_title LIKE '영%' AND job_title LIKE '%텔';
Empty set (0.00 sec)
mysql> select * from celeb where job_title LIKE '영%'AND job_title LIKE '%텔%';
+----+-----------+------------+------+------+-------------------------+----------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+----------------------+
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+----------------------+
1 row in set (0.00 sec)
mysql> select * from celeb where job_title LIKE '영%'AND job_title LIKE '%텔';
Empty set (0.00 sec)
mysql> select * from celeb where job_title LIKE '영%'AND job_title LIKE '텔%';
Empty set (0.00 sec)
mysql> select * from celeb where NOT job_title LIKE '%영%' OR job_title LIKE '%텔%';
+----+-----------+------------+------+------+-------------------------+--------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+--------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 2 | 이미주 | 1994-09-23 | 28 | F | 가수 | 울림엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 7 | 이수연 | 1999-05-03 | 23 | F | 가수 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+--------------------------+
6 rows in set (0.00 sec)
mysql> mysql> select from celeb where NOT job_title LIKE '%영%' OR NOT job_title LIKE '%텔%';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql> select from celeb where NOT job_title LIKE '%영%' OR NOT job_title LIK' at line 1
mysql> mysql> select from celeb where NOT job_title LIKE '%영%' AND NOT job_title LIKE '%텔%';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql> select from celeb where NOT job_title LIKE '%영%' AND NOT job_title LI' at line 1
mysql> select * from celeb where job_title LIKE '%,%';
+----+-----------+------------+------+------+-------------------------+------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
| 6 | 차승원 | 1970-06-07 | 48 | M | 영화배우, 모델 | YG엔터테인먼트 |
+----+-----------+------------+------+------+-------------------------+------------------------+
4 rows in set (0.00 sec)
mysql> select * from celeb where job_title LIKE '%,%' AND NOT job_title LIKE '%영화배우%' OR job_title LIKE '%텔런트%';
+----+-----------+------------+------+------+-------------------------+------------------------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+-------------------------+------------------------+
| 1 | 아이유 | 1993-05-16 | 29 | F | 가수, 텔런트 | EDAM엔터테인먼트 |
| 3 | 송강 | 1994-04-23 | 28 | M | 텔런트 | 나무엑터스 |
| 4 | 강동원 | 1981-01-18 | 41 | M | 영화배우, 텔런트 | YG엔터테인먼트 |
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
+----+-----------+------------+------+------+-------------------------+------------------------+
4 rows in set (0.00 sec)
mysql> select * from celeb
-> where
-> (job_title LIKE '%,%')
-> AND
-> NOT (job_title LIKE '%영화배우%' OR job_title LIKE '%텔런%');
+----+-----------+------------+------+------+---------------+-----------+
| ID | NAME | BIRTHDAY | AGE | SEX | JOB_TITLE | AGENCY |
+----+-----------+------------+------+------+---------------+-----------+
| 5 | 유재석 | 1972-08-14 | 50 | M | MC, 개그맨 | 안테나 |
+----+-----------+------------+------+------+---------------+-----------+
1 row in set (0.00 sec)
LIKE 실습 문제풀이 차례