Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 26

Enter password: **********

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 11
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, 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> use demo;


Database changed
mysql> show tables;
+----------------+
| Tables_in_demo |
+----------------+
| customer |
| orders |
| salesman |
+----------------+
3 rows in set (0.00 sec)

mysql> desc salesman;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
+-------------+--------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> alter table salesman add salary numeric(10,2) not null;


Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> dessc salesman;


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 'dessc
salesman' at line 1
mysql> desc salesman;
+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
+-------------+---------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> alter table salesman add district varchar(20) after city;


Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc salesman;
+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
+-------------+---------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> alter table salesman add Se varchar(3) first;


Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc salesman;


+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| Se | varchar(3) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
+-------------+---------------+------+-----+---------+-------+
7 rows in set (0.01 sec)

mysql> alter table salesman add(x varchar(5), y varchar(5), z varchar(5));


Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc salesman;


+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| Se | varchar(3) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
| x | varchar(5) | YES | | NULL | |
| y | varchar(5) | YES | | NULL | |
| z | varchar(5) | YES | | NULL | |
+-------------+---------------+------+-----+---------+-------+
10 rows in set (0.00 sec)

mysql> alter table salesman modify column city varchar(40);


Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table salesman modify z z_new varchar(8);


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 'z_new
varchar(8)' at line 1
mysql> alter table salesman change z z_new varchar(8);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc salesman;


+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| Se | varchar(3) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
| x | varchar(5) | YES | | NULL | |
| y | varchar(5) | YES | | NULL | |
| z_new | varchar(8) | YES | | NULL | |
+-------------+---------------+------+-----+---------+-------+
10 rows in set (0.01 sec)

mysql> show tables;


+----------------+
| Tables_in_demo |
+----------------+
| customer |
| orders |
| salesman |
+----------------+
3 rows in set (0.01 sec)

mysql> desc orders;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | YES | | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | YES | | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table orders add primary key(salesman_id);


Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc orders;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | YES | | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> desc customer;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | YES | | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table customer add primary key(salesman_id);


Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc customer;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | YES | | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> create table city(


-> name varchar(30),
-> pincode varchar(6));
Query OK, 0 rows affected (0.03 sec)

mysql> desc city;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(30) | YES | | NULL | |
| pincode | varchar(6) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

mysql> alter table city constraint "primary key violation" add primary key (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
'constraint "primary key violation" add primary key (name)' at line 1
mysql> alter table city constraint "primary key violation" add primary key(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
'constraint "primary key violation" add primary key(name)' at line 1
mysql> alter table city add primary key(name);
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table city constraint "primary key violation" add primary key(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
'constraint "primary key violation" add primary key(name)' at line 1
mysql> alter table city modify primary key(name) primary key(pincode);
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 'primary
key(name) primary key(pincode)' at line 1
mysql> desc city
-> ;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(30) | NO | PRI | NULL | |
| pincode | varchar(6) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> show tables;


+----------------+
| Tables_in_demo |
+----------------+
| city |
| customer |
| orders |
| salesman |
+----------------+
4 rows in set (0.00 sec)

mysql> desc orders;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | YES | | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> desc customer;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | YES | | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

Enter password: **********


Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, 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;


+--------------------+
| Database |
+--------------------+
| demo |
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
7 rows in set (0.03 sec)

mysql> use demo;


Database changed
mysql> show tables;
+----------------+
| Tables_in_demo |
+----------------+
| city |
| customer |
| orders |
| salesman |
+----------------+
4 rows in set (0.00 sec)

mysql> desc salesman;


+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| Se | varchar(3) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
| x | varchar(5) | YES | | NULL | |
| y | varchar(5) | YES | | NULL | |
| z_new | varchar(8) | YES | | NULL | |
+-------------+---------------+------+-----+---------+-------+
10 rows in set (0.00 sec)

mysql> desc orders;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | YES | | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> desc customer;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | YES | | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> foreign key salesman(salesman_id) references customer(salesman_id);


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 'foreign
key salesman(salesman_id) references customer(salesman_id)' at line 1
mysql> alter table orders drop primary key add primary key(ord_no);
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
primary key(ord_no)' at line 1
mysql> alter table orders drop primary key, add primary key(ord_no);
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc orders;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | NO | PRI | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> foreign key(customer_id) references customer(customer_id);


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 'foreign
key(customer_id) references customer(customer_id)' at line 1
mysql> desc orders;
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | NO | PRI | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table orders foreign key(customer_id) references


customer(customer_id);
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 'foreign
key(customer_id) references customer(customer_id)' at line 1
mysql> desc customer;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | YES | | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table customer drop primary key, add primary key(customer_id);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc customer;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | NO | PRI | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> foreign key(customer_id) references customer(customer_id),


-> foreign key(salesman_id) references salesman(salesman_id);
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 'foreign
key(customer_id) references customer(customer_id),
foreign key(salesman_' at line 1
mysql> desc salesman;
+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| Se | varchar(3) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
| x | varchar(5) | YES | | NULL | |
| y | varchar(5) | YES | | NULL | |
| z_new | varchar(8) | YES | | NULL | |
+-------------+---------------+------+-----+---------+-------+
10 rows in set (0.00 sec)

mysql> alter table salesman drop(x, y, z_new);


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 '(x, y,
z_new)' at line 1
mysql> alter table salesman drop x, drop y;
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table salesman drop z_new;


Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc salesman;


+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| Se | varchar(3) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
+-------------+---------------+------+-----+---------+-------+
7 rows in set (0.01 sec)

mysql> alter table orders add foreign key(customer_id) references


customer(customer_id);
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc orders;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | NO | PRI | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | MUL | NULL | |
| salesman_id | varchar(5) | NO | | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> desc customer;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | NO | PRI | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> alter table orders add foreign key(salesman_id) references


salesman(salesman_id);
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc orders;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | NO | PRI | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | MUL | NULL | |
| salesman_id | varchar(5) | NO | MUL | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> alter table customer add foreign key(salesman_id) references


salesman(salesman_id);
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc orders;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | NO | PRI | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | MUL | NULL | |
| salesman_id | varchar(5) | NO | MUL | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> desc customer;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | NO | PRI | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | MUL | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql>Enter password: **********


Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, 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;


+--------------------+
| Database |
+--------------------+
| demo |
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
7 rows in set (0.01 sec)
mysql> use demo;
Database changed
mysql> show tables;
+----------------+
| Tables_in_demo |
+----------------+
| city |
| customer |
| orders |
| salesman |
+----------------+
4 rows in set (0.01 sec)

mysql> desc customer;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | NO | PRI | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | MUL | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql> insert into salesman(customer_id,cust_name,city,grade,salesman_id)


values(5001,James Hoog,New York,0.15);
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 'Hoog,New
York,0.15)' at line 1
mysql> insert into salesman(customer_id,cust_name,city,grade,salesman_id)
values(5001,James Hoog,New York,0.15);select * from sa^C
mysql> select * from salesman;
Empty set (0.02 sec)

mysql> insert into salesman(salesman_id,name,city,commission) values(5001,James


Hoog,New York,0.15);
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 'Hoog,New
York,0.15)' at line 1
mysql> insert into salesman
-> (salesman_id,name,city,commission)
-> values
-> (5001,James Hoog,New York,0.15);
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 'Hoog,New
York,0.15)' at line 4
mysql> insert into salesman
-> (salesman_id,name,city,commission)
-> values
-> ("5001","James Hoog","New York","0.15");
ERROR 1364 (HY000): Field 'salary' doesn't have a default value
mysql> desc salesman;
+-------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| Se | varchar(3) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
| salary | decimal(10,2) | NO | | NULL | |
+-------------+---------------+------+-----+---------+-------+
7 rows in set (0.00 sec)

mysql> insert into salesman(salesman_id,name,city,commission,salary) values


("5001","James Hoog","New York",0.15,null);
ERROR 1048 (23000): Column 'salary' cannot be null
mysql> insert into salesman(salesman_id,name,city,commission,salary) values
("5001","James Hoog","New York",0.15,not null);
ERROR 1048 (23000): Column 'salary' cannot be null
mysql> drop salary from salesman;
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 'salary
from salesman' at line 1
mysql> alter table salesman drop column salary;
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc salesman;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| Se | varchar(3) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
+-------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql> insert into salesman(salesman_id,name,city,commission) values ("5001","James


Hoog","New York",0.15);
Query OK, 1 row affected (0.01 sec)

mysql> insert into salesman(salesman_id,name,city,commission) values ("5002","Nail


Knite","Paris",0.13);
Query OK, 1 row affected (0.00 sec)

mysql> insert into salesman(salesman_id,name,city,commission) values ("5003","Pit


Alex","London",0.11);
Query OK, 1 row affected (0.00 sec)

mysql> insert into salesman(salesman_id,name,city,commission) values ("5006","Mc


Lyon","Paris",0.14);
Query OK, 1 row affected (0.00 sec)

mysql> update salesman


-> set salesman_id = "5005"
-> where name = "Pit Alex";
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from salesman;


+------+-------------+------------+----------+----------+------------+
| Se | salesman_id | name | city | district | commission |
+------+-------------+------------+----------+----------+------------+
| NULL | 5001 | James Hoog | New York | NULL | 0.15 |
| NULL | 5002 | Nail Knite | Paris | NULL | 0.13 |
| NULL | 5005 | Pit Alex | London | NULL | 0.11 |
| NULL | 5006 | Mc Lyon | Paris | NULL | 0.14 |
+------+-------------+------------+----------+----------+------------+
4 rows in set (0.00 sec)

mysql> insert into salesman(salesman_id,name,city,commission) values ("5007","Paul


Adam","Rome",0.13);
Query OK, 1 row affected (0.00 sec)

mysql> insert into salesman(salesman_id,name,city,commission) values


("5003","Lauson Hen","San Jose",0.12);
Query OK, 1 row affected (0.00 sec)

mysql> select * from salesman;


+------+-------------+------------+----------+----------+------------+
| Se | salesman_id | name | city | district | commission |
+------+-------------+------------+----------+----------+------------+
| NULL | 5001 | James Hoog | New York | NULL | 0.15 |
| NULL | 5002 | Nail Knite | Paris | NULL | 0.13 |
| NULL | 5003 | Lauson Hen | San Jose | NULL | 0.12 |
| NULL | 5005 | Pit Alex | London | NULL | 0.11 |
| NULL | 5006 | Mc Lyon | Paris | NULL | 0.14 |
| NULL | 5007 | Paul Adam | Rome | NULL | 0.13 |
+------+-------------+------------+----------+----------+------------+
6 rows in set (0.00 sec)

mysql> desc customer;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| customer_id | varchar(5) | NO | PRI | NULL | |
| cust_name | varchar(30) | YES | | NULL | |
| city | varchar(30) | YES | | NULL | |
| grade | varchar(5) | YES | | NULL | |
| salesman_id | varchar(5) | NO | MUL | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> insert into customer(customer_id,cust_name,city,grade,salesman_id)


values("3002","Nick Rimando","New York","100","5001");
Query OK, 1 row affected (0.01 sec)

mysql> insert into customer(customer_id,cust_name,city,grade,salesman_id)


values("3007","Brav Davis","New York","200","5001");
Query OK, 1 row affected (0.00 sec)

mysql> insert into customer(customer_id,cust_name,city,grade,salesman_id)


values("3005","Graham Zusi","California","200","5002");
Query OK, 1 row affected (0.00 sec)

mysql> insert into customer(customer_id,cust_name,city,grade,salesman_id)


values("3008","Julian Green","London","300","5002");
Query OK, 1 row affected (0.00 sec)

mysql> insert into customer(customer_id,cust_name,city,grade,salesman_id)


values("3004","Fabian Johnson","Paris","300","5006");
Query OK, 1 row affected (0.00 sec)

mysql> insert into customer(customer_id,cust_name,city,grade,salesman_id)


values("3009","Geoff Cameron","Berlin","100","5003");
Query OK, 1 row affected (0.00 sec)

mysql> insert into customer(customer_id,cust_name,city,grade,salesman_id)


values("3003","Jozy Altidor","Moscow","200","5007");
Query OK, 1 row affected (0.01 sec)

mysql> insert into customer(customer_id,cust_name,city,grade,salesman_id)


values("3001","Brad Guzan","London","","5005");
Query OK, 1 row affected (0.00 sec)

mysql> selct * from customer;


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 'selct *
from customer' at line 1
mysql> select * from customer;
+-------------+----------------+------------+-------+-------------+
| customer_id | cust_name | city | grade | salesman_id |
+-------------+----------------+------------+-------+-------------+
| 3001 | Brad Guzan | London | | 5005 |
| 3002 | Nick Rimando | New York | 100 | 5001 |
| 3003 | Jozy Altidor | Moscow | 200 | 5007 |
| 3004 | Fabian Johnson | Paris | 300 | 5006 |
| 3005 | Graham Zusi | California | 200 | 5002 |
| 3007 | Brav Davis | New York | 200 | 5001 |
| 3008 | Julian Green | London | 300 | 5002 |
| 3009 | Geoff Cameron | Berlin | 100 | 5003 |
+-------------+----------------+------------+-------+-------------+
8 rows in set (0.00 sec)

mysql> desc orders;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| ord_no | decimal(5,0) | NO | PRI | NULL | |
| purch_amt | decimal(8,2) | YES | | NULL | |
| ord_date | date | YES | | NULL | |
| customer_id | varchar(5) | YES | MUL | NULL | |
| salesman_id | varchar(5) | NO | MUL | NULL | |
+-------------+--------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70001,150.5,2012-10-05,"3005","5002");
ERROR 1292 (22007): Incorrect date value: '1997' for column 'ord_date' at row 1
mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)
values(70001,150.5,"2012-10-05","3005","5002");
Query OK, 1 row affected (0.00 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70009,270.65,"2012-09-10","3001","5005");
Query OK, 1 row affected (0.00 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70002,65.26,"2012-10-05","3002","5001");
Query OK, 1 row affected (0.00 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70004,110.5,"2012-08-17","3009","5003");
Query OK, 1 row affected (0.00 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70007,948.5,"2012-09-10","3005","5002");
Query OK, 1 row affected (0.00 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70005,2400.6,"2012-07-27","3007","5001");
Query OK, 1 row affected (0.00 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70008,5760,"2012-09-10","3002","5001");
Query OK, 1 row affected (0.01 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70010,1983.43,"2012-10-10","3004","5006");
Query OK, 1 row affected (0.00 sec)

mysql> select * from orders;


+--------+-----------+------------+-------------+-------------+
| ord_no | purch_amt | ord_date | customer_id | salesman_id |
+--------+-----------+------------+-------------+-------------+
| 70001 | 150.50 | 2012-10-05 | 3005 | 5002 |
| 70002 | 65.26 | 2012-10-05 | 3002 | 5001 |
| 70004 | 110.50 | 2012-08-17 | 3009 | 5003 |
| 70005 | 2400.60 | 2012-07-27 | 3007 | 5001 |
| 70007 | 948.50 | 2012-09-10 | 3005 | 5002 |
| 70008 | 5760.00 | 2012-09-10 | 3002 | 5001 |
| 70009 | 270.65 | 2012-09-10 | 3001 | 5005 |
| 70010 | 1983.43 | 2012-10-10 | 3004 | 5006 |
+--------+-----------+------------+-------------+-------------+
8 rows in set (0.00 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70003,2480.4,"2012-10-10","3009","5003");
Query OK, 1 row affected (0.00 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70012,250.45,"2012-06-27","3008","5002");
Query OK, 1 row affected (0.00 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70011,75.29,"2012-08-17","3003","5007");
Query OK, 1 row affected (0.01 sec)

mysql> insert into orders(ord_no,purch_amt,ord_date,customer_id,salesman_id)


values(70013,3045.6,"2012-04-25","3002","5001");
Query OK, 1 row affected (0.00 sec)

mysql> select * from orders


-> ;
+--------+-----------+------------+-------------+-------------+
| ord_no | purch_amt | ord_date | customer_id | salesman_id |
+--------+-----------+------------+-------------+-------------+
| 70001 | 150.50 | 2012-10-05 | 3005 | 5002 |
| 70002 | 65.26 | 2012-10-05 | 3002 | 5001 |
| 70003 | 2480.40 | 2012-10-10 | 3009 | 5003 |
| 70004 | 110.50 | 2012-08-17 | 3009 | 5003 |
| 70005 | 2400.60 | 2012-07-27 | 3007 | 5001 |
| 70007 | 948.50 | 2012-09-10 | 3005 | 5002 |
| 70008 | 5760.00 | 2012-09-10 | 3002 | 5001 |
| 70009 | 270.65 | 2012-09-10 | 3001 | 5005 |
| 70010 | 1983.43 | 2012-10-10 | 3004 | 5006 |
| 70011 | 75.29 | 2012-08-17 | 3003 | 5007 |
| 70012 | 250.45 | 2012-06-27 | 3008 | 5002 |
| 70013 | 3045.60 | 2012-04-25 | 3002 | 5001 |
+--------+-----------+------------+-------------+-------------+
12 rows in set (0.00 sec)

Enter password: **********


Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, 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> use demo;


Database changed
mysql> show tables;
+----------------+
| Tables_in_demo |
+----------------+
| city |
| customer |
| orders |
| salesman |
+----------------+
4 rows in set (0.00 sec)

mysql> select customer.cust_name, salesman.name, salesman.city from customer,


salesman where salesman.city = customer.city;
+----------------+------------+----------+
| cust_name | name | city |
+----------------+------------+----------+
| Brad Guzan | Pit Alex | London |
| Nick Rimando | James Hoog | New York |
| Fabian Johnson | Mc Lyon | Paris |
| Fabian Johnson | Nail Knite | Paris |
| Brav Davis | James Hoog | New York |
| Julian Green | Pit Alex | London |
+----------------+------------+----------+
6 rows in set (0.01 sec)

mysql> select customer.cust_name, salesman.salesman from customer, salesman where


customer.salesman_id = salesman.salesman_id;
ERROR 1054 (42S22): Unknown column 'salesman.salesman' in 'field list'
mysql> select customer.cust_name, salesman.salesman from customer, salesman where
customer.salesman_id = salesman.salesman_id;
ERROR 1054 (42S22): Unknown column 'salesman.salesman' in 'field list'
mysql> desc salesman;
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| Se | varchar(3) | YES | | NULL | |
| salesman_id | varchar(5) | NO | PRI | NULL | |
| name | varchar(30) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| district | varchar(20) | YES | | NULL | |
| commission | decimal(8,2) | YES | | NULL | |
+-------------+--------------+------+-----+---------+-------+
6 rows in set (0.01 sec)

mysql> select customer.cust_name, salesman.name from customer, salesman where


customer.salesman_id = salesman.salesman_id;
+----------------+------------+
| cust_name | name |
+----------------+------------+
| Nick Rimando | James Hoog |
| Brav Davis | James Hoog |
| Graham Zusi | Nail Knite |
| Julian Green | Nail Knite |
| Geoff Cameron | Lauson Hen |
| Brad Guzan | Pit Alex |
| Fabian Johnson | Mc Lyon |
| Jozy Altidor | Paul Adam |
+----------------+------------+
8 rows in set (0.00 sec)

mysql> select ord_no,cust_name,orders.customer_id,orders.salesman.id from orders,


customer where customer.salesman_id=orders.salesman_id not customer.city =
salesman_city;
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
'customer.city = salesman_city' at line 1
mysql> select ord_no,cust_name,orders.customer_id,orders.salesman.id from orders,
customer where customer.salesman_id=orders.salesman_id not customer.city =
salesman.city;
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
'customer.city = salesman.city' at line 1
mysql> select ord_no,cust_name,orders.customer_id,orders.salesman.id from orders,
customer where customer.salesman_id=orders.salesman_id and not customer.city =
salesman.city;
ERROR 1054 (42S22): Unknown column 'orders.salesman.id' in 'field list'
mysql> select ord_no,cust_name,orders.customer_id,orders.salesman_id from orders,
customer where customer.salesman_id=orders.salesman_id and not customer.city =
salesman.city;
ERROR 1054 (42S22): Unknown column 'salesman.city' in 'where clause'
mysql> select ord_no,cust_name,orders.customer_id,orders.salesman_id from orders,
customer, salesman where customer.salesman_id=orders.salesman_id and not
customer.city = salesman.city;
+--------+----------------+-------------+-------------+
| ord_no | cust_name | customer_id | salesman_id |
+--------+----------------+-------------+-------------+
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
+--------+----------------+-------------+-------------+
100 rows in set (0.00 sec)

mysql> select
orders.ord_no,customer.cust_name,orders.customer_id,orders.salesman_id from orders,
customer, salesman where customer.salesman_id=orders.salesman_id and not
customer.city = salesman.city;
+--------+----------------+-------------+-------------+
| ord_no | cust_name | customer_id | salesman_id |
+--------+----------------+-------------+-------------+
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
+--------+----------------+-------------+-------------+
100 rows in set (0.00 sec)

mysql> select
orders.ord_no,customer.cust_name,orders.customer_id,orders.salesman_id from orders,
customer, salesman where customer.salesman_id=orders.salesman_id and
customer.city != salesman.city;
+--------+----------------+-------------+-------------+
| ord_no | cust_name | customer_id | salesman_id |
+--------+----------------+-------------+-------------+
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70009 | Brad Guzan | 3001 | 5005 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
+--------+----------------+-------------+-------------+
100 rows in set (0.00 sec)

mysql> select distinct


orders.ord_no,customer.cust_name,orders.customer_id,orders.salesman_id from orders,
customer, salesman where customer.salesman_id=orders.salesman_id and
customer.city != salesman.city;
+--------+----------------+-------------+-------------+
| ord_no | cust_name | customer_id | salesman_id |
+--------+----------------+-------------+-------------+
| 70009 | Brad Guzan | 3001 | 5005 |
| 70002 | Nick Rimando | 3002 | 5001 |
| 70005 | Nick Rimando | 3007 | 5001 |
| 70008 | Nick Rimando | 3002 | 5001 |
| 70013 | Nick Rimando | 3002 | 5001 |
| 70011 | Jozy Altidor | 3003 | 5007 |
| 70010 | Fabian Johnson | 3004 | 5006 |
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Graham Zusi | 3008 | 5002 |
| 70002 | Brav Davis | 3002 | 5001 |
| 70005 | Brav Davis | 3007 | 5001 |
| 70008 | Brav Davis | 3002 | 5001 |
| 70013 | Brav Davis | 3002 | 5001 |
| 70001 | Julian Green | 3005 | 5002 |
| 70007 | Julian Green | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
+--------+----------------+-------------+-------------+
19 rows in set (0.00 sec)

mysql> select
orders.ord_no,customer.cust_name,orders.customer_id,orders.salesman_id from orders,
customer, salesman where customer.customer_id=orders.customer_id and
customer.city != salesman.city and customer.salesman_id=salesman.salesman_id;
+--------+---------------+-------------+-------------+
| ord_no | cust_name | customer_id | salesman_id |
+--------+---------------+-------------+-------------+
| 70001 | Graham Zusi | 3005 | 5002 |
| 70007 | Graham Zusi | 3005 | 5002 |
| 70012 | Julian Green | 3008 | 5002 |
| 70003 | Geoff Cameron | 3009 | 5003 |
| 70004 | Geoff Cameron | 3009 | 5003 |
| 70011 | Jozy Altidor | 3003 | 5007 |
+--------+---------------+-------------+-------------+
6 rows in set (0.00 sec)

mysql> select orders.ord_no, customer.cust_name from customer, orders where


orders.customer_id=customer.customer_id;
+--------+----------------+
| ord_no | cust_name |
+--------+----------------+
| 70009 | Brad Guzan |
| 70002 | Nick Rimando |
| 70008 | Nick Rimando |
| 70013 | Nick Rimando |
| 70011 | Jozy Altidor |
| 70010 | Fabian Johnson |
| 70001 | Graham Zusi |
| 70007 | Graham Zusi |
| 70005 | Brav Davis |
| 70012 | Julian Green |
| 70003 | Geoff Cameron |
| 70004 | Geoff Cameron |
+--------+----------------+
12 rows in set (0.00 sec)

mysql> select customer.cust_name as "Customer", customer.grade as "Grade" from


customer, grade where grade = not null and orders.customer_id =
customer.customer_id;
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 'not null
and orders.customer_id = customer.customer_id' at line 1
mysql> select customer.cust_name as "Customer", customer.grade as "Grade" from
customer, orders where grade = not null and orders.customer_id =
customer.customer_id;
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 'not null
and orders.customer_id = customer.customer_id' at line 1
mysql> select customer.cust_name as "Customer", customer.grade as "Grade" from
customer, orders where orders.customer_id = customer.customer_id;
+----------------+-------+
| Customer | Grade |
+----------------+-------+
| Brad Guzan | |
| Nick Rimando | 100 |
| Nick Rimando | 100 |
| Nick Rimando | 100 |
| Jozy Altidor | 200 |
| Fabian Johnson | 300 |
| Graham Zusi | 200 |
| Graham Zusi | 200 |
| Brav Davis | 200 |
| Julian Green | 300 |
| Geoff Cameron | 100 |
| Geoff Cameron | 100 |
+----------------+-------+
12 rows in set (0.00 sec)

mysql> select customer.cust_name as "Customer", customer.grade as "Grade" from


customer, orders where grade not null and orders.customer_id =
customer.customer_id;
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 'null and
orders.customer_id = customer.customer_id' at line 1
mysql> select customer.cust_name as "Customer", customer.grade as "Grade" from
customer, orders where grade = not null and orders.customer_id =
customer.customer_id;
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 'not null
and orders.customer_id = customer.customer_id' at line 1
mysql> select customer.cust_name as "Customer", customer.grade as "Grade" from
customer, orders where grade is not null and orders.customer_id =
customer.customer_id;
+----------------+-------+
| Customer | Grade |
+----------------+-------+
| Brad Guzan | |
| Nick Rimando | 100 |
| Nick Rimando | 100 |
| Nick Rimando | 100 |
| Jozy Altidor | 200 |
| Fabian Johnson | 300 |
| Graham Zusi | 200 |
| Graham Zusi | 200 |
| Brav Davis | 200 |
| Julian Green | 300 |
| Geoff Cameron | 100 |
| Geoff Cameron | 100 |
+----------------+-------+
12 rows in set (0.00 sec)

mysql> select customer.cust_name as "Customer", customer.grade as "Grade" from


customer, orders where grade is null and orders.customer_id =
customer.customer_id;
Empty set (0.00 sec)

mysql> select customer.cust_name as "Customer", customer.grade as "Grade" from


customer, orders where grade is not null and orders.customer_id =
customer.customer_id;
+----------------+-------+
| Customer | Grade |
+----------------+-------+
| Brad Guzan | |
| Nick Rimando | 100 |
| Nick Rimando | 100 |
| Nick Rimando | 100 |
| Jozy Altidor | 200 |
| Fabian Johnson | 300 |
| Graham Zusi | 200 |
| Graham Zusi | 200 |
| Brav Davis | 200 |
| Julian Green | 300 |
| Geoff Cameron | 100 |
| Geoff Cameron | 100 |
+----------------+-------+
12 rows in set (0.00 sec)

mysql>

You might also like