You are on page 1of 24

ASSIGNMENT – 01

CREATE DATABSE WITH NAME lab1DBMS.


1. USE DATABASE lab1DBMS
2. CREATE TWO TABLES WITH NAME “EMPLOYEE” WITH FOLLOWING 4 FIELDS – ENO ,
ENAME , SALARY , DNO .
3. SECOND TABLE ”DEPARTMENT” – DNO , DNAME , DLOC.
4. INSERT 5 VALUES IN EMPLOYEE AND DEPARTMENT.
5. DISPLAY RECORDS OF BOTH TABLES.
6. DISPLAY THE EMPLOYEE NAME OF THOSE EMPLOYEE WHO ARE EARNING MORE THAN
5000 RUPEES.
7. DISPLAY NAME OF DEPARTMENT WHICH IS LOCATED IN SOUTH.
8. DISPLAY THE NAME OF EMPLOYEE WHO ARE WORKING IN DEPARTMENT WHICH IS
LOCATED IN NORTH.

COMMANDS
Q1. mysql> create database A1;
Query OK, 1 row affected (0.02 sec)

mysql> use A1;


Database changed
mysql> create table employee(eno int , ename char(10), salary int , dno int );
Query OK, 0 rows affected (0.04 sec)

mysql> mysql> insert into employee values(1 , 'ram' , 50000 , 001);


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> insert into employee values(1 , 'ram' , 50000 , 001)' at line 1
mysql> Query OK, 1 row affected (0.06 sec)
->
-> mysql> insert into employee values(2 , 'shym' , 150000 , 002);
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 'Query OK, 1 row affected (0.06 sec)

mysql> insert into employee values(2 , 's' at line 1


mysql> Query OK, 1 row affected (0.06 sec)
->
-> mysql> insert into employee values(3 , 'shelly' , 60000 , 003);

SHASHIKANT CHAUBEY 2000300100207


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 'Query OK, 1 row affected (0.06 sec)

mysql> insert into employee values(3 , 's' at line 1


mysql> Query OK, 1 row affected (0.06 sec)
->
-> mysql> insert into employee values(4 , 'kavin' , 70000 , 004);
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 'Query OK, 1 row affected (0.06 sec)

mysql> insert into employee values(4 , 'k' at line 1


mysql> insert into employee values(1 , 'Rohan' , 50000 , 001);
Query OK, 1 row affected (0.02 sec)

mysql> insert into employee values(2 , 'mohan' , 150000 , 002);


Query OK, 1 row affected (0.01 sec)

mysql> insert into employee values(3 , 'Sohan' , 60000 , 003);


Query OK, 1 row affected (0.01 sec)

mysql> insert into employee values(4 , 'Shyam' , 70000 , 004);


Query OK, 1 row affected (0.01 sec)

mysql> insert into employee values(5 , 'sachin' , 80000 , 005);


Query OK, 1 row affected (0.01 sec)

mysql> create table department(dno int , dname char(10), dloc char(10));


Query OK, 0 rows affected (0.02 sec)

mysql> insert into department values(001, 'writing' , 'north');


Query OK, 1 row affected (0.00 sec)

mysql> insert into department values(002, 'editor' , 'east');


Query OK, 1 row affected (0.01 sec)

mysql> insert into department values(003, 'printer' , 'south');


Query OK, 1 row affected (0.01 sec)

SHASHIKANT CHAUBEY 2000300100207


mysql> insert into department values(004, 'hr' , 'west');
Query OK, 1 row affected (0.01 sec)

mysql> insert into department values(005, 'viewer' , 'south');


Query OK, 1 row affected (0.01 sec)

mysql> select * from department;


+------+---------+-------+
| dno | dname | dloc |
+------+---------+-------+
| 1 | writing | north |
| 2 | editor | east |
| 3 | printer | south |
| 4 | hr | west |
| 5 | viewer | south |
+------+---------+-------+
5 rows in set (0.00 sec)

mysql> select eno , ename from employee where salary>50000;


+------+--------+
| eno | ename |
+------+--------+
| 2 | mohan |
| 3 | Sohan |
| 4 | Shyam |
| 5 | sachin |
+------+--------+
4 rows in set (0.00 sec)

mysql> select dname from department where dloc ='south';


+---------+
| dname |
+---------+
| printer |
| viewer |
+---------+
2 rows in set (0.00 sec)

mysql> select employee.ename from employee, department where


employee.dno = department.dno and department.dloc = 'north';

SHASHIKANT CHAUBEY 2000300100207


+-------+
| ename |
+-------+
| Rohan |
+-------+
1 row in set (0.01 sec)

SHASHIKANT CHAUBEY 2000300100207


ASSIGNMENT – 2

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

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


Your MySQL connection id is 9
Server version: 8.0.30 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.

Q1. mysql> create database lab1DBMS;


Query OK, 1 row affected (0.01 sec)

Q2. mysql> use lab1DBMS;


Database changed

mysql> select * from employee;


+-------+--------+-----------+------+------------+--------+--------+-----------------+
| EmpNo | EName | Job | MGR | H_Date | Salary | DeptNo |
Department_Name |
+-------+--------+-----------+------+------------+--------+--------+-----------------+
| 7369 | SMITH | CLERK | 7902 | 1981-12-17 | 800 | 20 | Research
|
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600 | 30 | Sales
|
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250 | 30 | Sales
|
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975 | 20 | Research
|
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250 | 30 | Sales
|
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850 | 30 | Sales
|

SHASHIKANT CHAUBEY 2000300100207


| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450 | 30 | Sales
|
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000 | 20 | Research
|
| 7839 | KING | PRESIDENT | 0 | 1981-11-17 | 5000 | 10 | Accounting
|
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500 | 30 | Sales
|
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100 | 20 | Research
|
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950 | 30 | Sales |
| 7902 | FORD | ANALYST | 7566 | 1981-12-04 | 3000 | 20 | Research
|
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300 | 10 | Accounting
|
+-------+--------+-----------+------+------------+--------+--------+-----------------+
14 rows in set (0.00 sec)

mysql> select * from Department;


+--------+------------+------------+
| DeptNo | DName | Loc |
+--------+------------+------------+
| 10 | Accounting | new jersey |
| 20 | Research | Dallas |
| 30 | Sales | Chicago |
| 40 | Operations | Boston |
+--------+------------+------------+
4 rows in set (0.00 sec)

mysql> select EName, Salary from employee;

SHASHIKANT CHAUBEY 2000300100207


+--------+--------+
| EName | Salary |
+--------+--------+
| SMITH | 800 |
| ALLEN | 1600 |
| WARD | 1250 |
| JONES | 2975 |
| MARTIN | 1250 |
| BLAKE | 2850 |
| CLARK | 2450 |
| SCOTT | 3000 |
| KING | 5000 |
| TURNER | 1500 |
| ADAMS | 1100 |
| JAMES | 950 |
| FORD | 3000 |
| MILLER | 1300 |
+--------+--------+
14 rows in set (0.00 sec)

mysql> > select * from employee where DeptNo=20;


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 '> select * from employee where DeptNo=20' at line 1
mysql> select * from employee where DeptNo = 20;
+-------+-------+---------+------+------------+--------+--------+-----------------+
| EmpNo | EName | Job | MGR | H_Date | Salary | DeptNo |
Department_Name |
+-------+-------+---------+------+------------+--------+--------+-----------------+
| 7369 | SMITH | CLERK | 7902 | 1981-12-17 | 800 | 20 | Research |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975 | 20 | Research
|
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000 | 20 | Research
|
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100 | 20 | Research
|
| 7902 | FORD | ANALYST | 7566 | 1981-12-04 | 3000 | 20 | Research
|
+-------+-------+---------+------+------------+--------+--------+-----------------+
5 rows in set (0.01 sec)

SHASHIKANT CHAUBEY 2000300100207


mysql> select ename,sal from employee where Salary>100;
ERROR 1054 (42S22): Unknown column 'sal' in 'field list'
mysql> select ename,salary from employee where Salary>100;
+--------+--------+
| ename | salary |
+--------+--------+
| SMITH | 800 |
| ALLEN | 1600 |
| WARD | 1250 |
| JONES | 2975 |
| MARTIN | 1250 |
| BLAKE | 2850 |
| CLARK | 2450 |
| SCOTT | 3000 |
| KING | 5000 |
| TURNER | 1500 |
| ADAMS | 1100 |
| JAMES | 950 |
| FORD | 3000 |
| MILLER | 1300 |
+--------+--------+
14 rows in set (0.00 sec)

mysql> select empno,mgr from employee;


+-------+------+
| empno | mgr |
+-------+------+
| 7369 | 7902 |
| 7499 | 7698 |
| 7521 | 7698 |
| 7566 | 7839 |
| 7654 | 7698 |
| 7698 | 7839 |
| 7782 | 7839 |
| 7788 | 7566 |
| 7839 | 0 |
| 7844 | 7698 |
| 7876 | 7788 |
| 7900 | 7698 |

SHASHIKANT CHAUBEY 2000300100207


| 7902 | 7566 |
| 7934 | 7782 |
+-------+------+
14 rows in set (0.00 sec)

mysql> select empno,job from employee where deptno=20;


+-------+---------+
| empno | job |
+-------+---------+
| 7369 | CLERK |
| 7566 | MANAGER |
| 7788 | ANALYST |
| 7876 | CLERK |
| 7902 | ANALYST |
+-------+---------+
5 rows in set (0.00 sec)

mysql> select ename from employee where job like 'salesman';


+--------+
| ename |
+--------+
| ALLEN |
| WARD |
| MARTIN |
| TURNER |
+--------+
4 rows in set (0.01 sec)

mysql> select ename from employee where hiredate<='1981-09-30';


ERROR 1054 (42S22): Unknown column 'hiredate' in 'where clause'
mysql> select ename from employee where h_date<='1981-09-30';
+--------+
| ename |
+--------+
| ALLEN |
| WARD |
| JONES |
| MARTIN |
| BLAKE |
| CLARK |

SHASHIKANT CHAUBEY 2000300100207


| TURNER |
+--------+
7 rows in set (0.01 sec)

mysql> select ename from employee where job not like 'manager';
+--------+
| ename |
+--------+
| SMITH |
| ALLEN |
| WARD |
| MARTIN |
| SCOTT |
| KING |
| TURNER |
| ADAMS |
| JAMES |
| FORD |
| MILLER |
+--------+
11 rows in set (0.00 sec)

mysql> select empno,ename,sal from employee where empno=7369 or 7521


-> or 7934 or 7788;
ERROR 1054 (42S22): Unknown column 'sal' in 'field list'
mysql> select empno,ename,salary from employee where empno=7369 or
7521
-> or 7934 or 7788;
+-------+--------+--------+
| empno | ename | salary |
+-------+--------+--------+
| 7369 | SMITH | 800 |
| 7499 | ALLEN | 1600 |
| 7521 | WARD | 1250 |
| 7566 | JONES | 2975 |
| 7654 | MARTIN | 1250 |
| 7698 | BLAKE | 2850 |
| 7782 | CLARK | 2450 |
| 7788 | SCOTT | 3000 |
| 7839 | KING | 5000 |

SHASHIKANT CHAUBEY 2000300100207


| 7844 | TURNER | 1500 |
| 7876 | ADAMS | 1100 |
| 7900 | JAMES | 950 |
| 7902 | FORD | 3000 |
| 7934 | MILLER | 1300 |
+-------+--------+--------+
14 rows in set (0.01 sec)

mysql> select ename,salary from employee where salary>=1000 and


salary<=2000;
+--------+--------+
| ename | salary |
+--------+--------+
| ALLEN | 1600 |
| WARD | 1250 |
| MARTIN | 1250 |
| TURNER | 1500 |
| ADAMS | 1100 |
| MILLER | 1300 |
+--------+--------+
6 rows in set (0.01 sec)

mysql> select ename from employee where deptno!=10 or 30 or 40;


+--------+
| ename |
+--------+
| SMITH |
| ALLEN |
| WARD |
| JONES |
| MARTIN |
| BLAKE |
| CLARK |
| SCOTT |
| KING |
| TURNER |
| ADAMS |
| JAMES |
| FORD |
| MILLER |

SHASHIKANT CHAUBEY 2000300100207


+--------+
14 rows in set (0.00 sec)

mysql> select ename from employee where hiredate<'1981-06-30' and


h_date>'1981-12-01';
ERROR 1054 (42S22): Unknown column 'hiredate' in 'where clause'
mysql> select ename from employee where h_date<'1981-06-30' and
h_date>'1981-12-01';
Empty set (0.00 sec)

mysql>

SHASHIKANT CHAUBEY 2000300100207


Assignmnent- 3
mysql> select * from department;
+--------+------------+----------+
| Deptno | Dname | Loc |
+--------+------------+----------+
| 1 | Accounting | New York |
| 2 | Research | Dallas |
| 3 | Sales | Chicago |
| 4 | Opertaions | Bostan |
+--------+------------+----------+
mysql> select * from employee;
| Empno | Ename | Job | Mgr | Hiredate | Sal | Comm | Deptno |
+-------+--------+----------+------+------------+------+------+--------+
| 7369 | smith | clerk | 7902 | 1981-12-17 | 800 | NULL | 2 |
| 7499 | allen | salesman | 7698 | 1981-02-20 | 1600 | 300 | 3 |
| 7521 | ward | salesman | 7698 | 1981-02-22 | 1250 | 500 | 3 |
| 7566 | jones | manager | 7839 | 1981-04-02 | 2975 | NULL | 2 |
| 7654 | martin | salesman | 7698 | 1981-09-28 | 1250 | 1400 | 3 |
| 7788 | scott | analyst | 7566 | 1982-12-09 | 3000 | NULL | 2 |
mysql> select * from employee,department ;
+-------+--------+----------+------+------------+------+------+--------+--------+----
--------+----------+
| Empno | Ename | Job | Mgr | Hiredate | Sal | Comm | Deptno |
Deptno | Dname | Loc
+-------+--------+----------+------+------------+------+------+--------+--------+----
--------+----------+
| 7369 | smith | clerk | 7902 | 1981-12-17 | 800 | NULL | 2 | 4 |
Opertaions | Bostan |
| 7369 | smith | clerk | 7902 | 1981-12-17 | 800 | NULL | 2 | 3 |
Sales | Chicago |
| 7369 | smith | clerk | 7902 | 1981-12-17 | 800 | NULL | 2 | 2 |
Research | Dallas |

SHASHIKANT CHAUBEY 2000300100207


| 7369 | smith | clerk | 7902 | 1981-12-17 | 800 | NULL | 2 | 1 |
Accounting | New York |
| 7499 | allen | salesman | 7698 | 1981-02-20 | 1600 | 300 | 3 | 4 |
Opertaions | Bostan |
| 7499 | allen | salesman | 7698 | 1981-02-20 | 1600 | 300 | 3 | 3 |
Sales | Chicago |
| 7499 | allen | salesman | 7698 | 1981-02-20 | 1600 | 300 | 3 | 2 |
Research | Dallas |
| 7499 | allen | salesman | 7698 | 1981-02-20 | 1600 | 300 | 3 | 1 |
Accounting | New York |
| 7521 | ward | salesman | 7698 | 1981-02-22 | 1250 | 500 | 3 | 4 |
Opertaions | Bostan |
| 7521 | ward | salesman | 7698 | 1981-02-22 | 1250 | 500 | 3 | 3 |
Sales | Chicago |
| 7521 | ward | salesman | 7698 | 1981-02-22 | 1250 | 500 | 3 | 2 |
Research | Dallas |
| 7521 | ward | salesman | 7698 | 1981-02-22 | 1250 | 500 | 3 | 1 |
Accounting | New York
| 7566 | jones | manager | 7839 | 1981-04-02 | 2975 | NULL | 2 | 4
| Opertaions | Bostan |
| 7566 | jones | manager | 7839 | 1981-04-02 | 2975 | NULL | 2 | 3
| Sales | Chicago |
| 7566 | jones | manager | 7839 | 1981-04-02 | 2975 | NULL | 2 | 2
| Research | Dallas |
| 7566 | jones | manager | 7839 | 1981-04-02 | 2975 | NULL | 2 | 1
| Accounting | New York
| 7654 | martin | salesman | 7698 | 1981-09-28 | 1250 | 1400 | 3 |
4 | Opertaions | Bostan
| 7654 | martin | salesman | 7698 | 1981-09-28 | 1250 | 1400 | 3 |
3 | Sales | Chicago |
| 7654 | martin | salesman | 7698 | 1981-09-28 | 1250 | 1400 | 3 |
2 | Research | Dallas |
| 7654 | martin | salesman | 7698 | 1981-09-28 | 1250 | 1400 | 3 |
1 | Accounting | NewYork

SHASHIKANT CHAUBEY 2000300100207


| 7788 | scott | analyst | 7566 | 1982-12-09 | 3000 | NULL | 2 | 4 |
Opertaions | Bostan |
| 7788 | scott | analyst | 7566 | 1982-12-09 | 3000 | NULL | 2 | 3 |
Sales | Chicago |
| 7788 | scott | analyst | 7566 | 1982-12-09 | 3000 | NULL | 2 | 2 |
Research | Dallas |
| 7788 | scott | analyst | 7566 | 1982-12-09 | 3000 | NULL | 2 | 1 |
Accounting | New York |
+-------+--------+----------+------+------------+------+------+--------+--------+----
--------+----------+
mysql> select Empno,Ename from employee where Comm>0 and
Deptno=3;
| Empno | Ename |
+-------+--------+
| 7499 | allen |
| 7521 | ward |
| 7654 | martin |
+-------+--------+
mysql> Delete from employee where Deptno=2;
mysql> select * from employee;
| Empno | Ename | Job | Mgr | Hiredate | Sal | Comm | Deptno |
| 7499 | allen | salesman | 7698 | 1981-02-20 | 1600 | 300 | 3 |
| 7521 | ward | salesman | 7698 | 1981-02-22 | 1250 | 500 | 3 |
| 7654 | martin | salesman | 7698 | 1981-09-28 | 1250 | 1400 | 3 |
+-------+--------+----------+------+------------+------+-----
mysql> select
employee.Ename,department.Deptno,department.Loc from
employee,department
where employee.Deptno=department.Deptno and
department.Loc='Chicago';
| Ename | Deptno | Loc |
| allen | 3 | Chicago |
| ward | 3 | Chicago |
| martin | 3 | Chicago |
+--------+--------+---------+

SHASHIKANT CHAUBEY 2000300100207


mysql> select department.Dname,employee.Mgr from
employee,department where
employee.Deptno=department.Deptno and Mgr=7521;
Empty set (0.00 sec)
mysql> select employee.Ename from employee,department where
employee.Deptno=department.Deptno and Sal>1000;
| Ename |
| allen |
| ward |
| martin |
mysql> select employee.Ename,department.Deptno from
employee,department where
employee.Deptno=department.Deptno and employee.Ename like
'a%';
| Ename | Deptno |
| allen | 3 |
mysql> select employee.Ename,department.Deptno from
employee,department where
employee.Deptno=department.Deptno and employee.Ename like
'_____';
+-------+--------+
| Ename | Deptno |
+-------+--------+
| allen | 3 |
+-------+--------+
mysql> select employee.Ename,department.Deptno from
employee,department where
employee.Deptno=department.Deptno and employee.Ename like
'_l%';
+-------+--------+
| Ename | Deptno |
+-------+--------+
| allen | 3 |

SHASHIKANT CHAUBEY 2000300100207


ASSIGNMENT - 4
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.30 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 Sailors;


Database changed
mysql> select * from sailor;
+-----+---------+--------+------+
| Sid | sname | rating | age |
+-----+---------+--------+------+
| 22 | Dustin | 7 | 45 |
| 29 | Bandish | 1 | 33 |
| 31 | Lovely | 8 | 55.5 |
| 32 | Anjana | 9 | 25.5 |
| 58 | Rustom | 10 | 35|
| 64 | Harish | 7 | 35 |
| 71 | Zubin | 10 | 16 |
| 74 | Harish | 9 | 35 |
| 85 | Anil | 3 | 25 |
| 95 | Bobby | 3 | 63 |
+-----+---------+--------+------+
10 rows in set (0.00 sec)

SHASHIKANT CHAUBEY 2000300100207


mysql> select * from reserve;
+------+------+------------+
| Sid | bid | day |
+------+------+------------+
| 22 | 101 | 1998-10-10 |
| 22 | 102 | 1998-10-10 |
| 22 | 103 | 1998-08-10 |
| 22 | 104 | 1998-07-10 |
| 31 | 102 | 1998-10-11 |
| 31 | 103 | 1998-06-11 |
| 31 | 104 | 1998-07-10 |
| 64 | 101 | 1998-10-09 |
| 64 | 102 | 1998-09-03 |
| 74 | 103 | 1998-08-03 |
+------+------+------------+
10 rows in set (0.00 sec)

mysql> select * from boat;


+------+-----------+-------+
| Bid | bname | color |
+------+-----------+-------+
| 101 | interlake | blue |
| 102 | interlake | red |
| 103 | clipper | green |
| 104 | marine | red |
+------+-----------+-------+
4 rows in set (0.00 sec)

Joining the Table

SHASHIKANT CHAUBEY 2000300100207


mysql> select * from sailor
-> join reserve
-> on reserve.Sid = sailor.Sid
-> join boat b
-> on b.Bid = reserve.bid;
+-----+--------+--------+------+------+------+------------+------+-----------+-------+
| Sid | sname | rating | age | Sid | bid | day | Bid | bname | color |
+-----+--------+--------+------+------+------+------------+------+-----------+-------+
| 22 | Dustin | 7 | 45 | 22 | 101 | 1998-10-10 | 101 | interlake | blue |
| 22 | Dustin | 7 | 45 | 22 | 102 | 1998-10-10 | 102 | interlake | red |
| 22 | Dustin | 7 | 45 | 22 | 103 | 1998-08-10 | 103 | clipper | green |
| 22 | Dustin | 7 | 45 | 22 | 104 | 1998-07-10 | 104 | marine | red |
| 31 | Lovely | 8 | 55.5 | 31 | 102 | 1998-10-11 | 102 | interlake | red |
| 31 | Lovely | 8 | 55.5 | 31 | 103 | 1998-06-11 | 103 | clipper | green |
| 31 | Lovely | 8 | 55.5 | 31 | 104 | 1998-07-10 | 104 | marine | red |
| 64 | Harish | 7 | 35 | 64 | 101 | 1998-10-09 | 101 | interlake | blue |
| 64 | Harish | 7 | 35 | 64 | 102 | 1998-09-03 | 102 | interlake | red |
| 74 | Harish | 9 | 35 | 74 | 103 | 1998-08-03 | 103 | clipper | green |
+-----+--------+--------+------+------+------+------------+------+-----------+-------+
10 rows in set (0.00 sec)

Q1. Find the names of sailors 'Who have reserved boat number 103.

SHASHIKANT CHAUBEY 2000300100207


mysql> select sname, bname, b.Bid from sailor
-> join reserve
-> on reserve.Sid = sailor.Sid
-> join boat b
-> on b.Bid = reserve.bid
-> where b.Bid = 103;
+--------+---------+------+
| sname | bname | Bid |
+--------+---------+------+
| Dustin | clipper | 103 |
| Lovely | clipper | 103 |
| Harish | clipper | 103 |
+--------+---------+------+
3 rows in set (0.00 sec)

Q2. Find the sids of sailors who have Reserved a red boat.

mysql> select sailor.sid, color from sailor


-> join reserve
-> on reserve.Sid = sailor.Sid
-> join boat b
-> on b.Bid = reserve.bid
-> where color = 'red';

+-----+-------+
| sid | color |
+-----+-------+
| 22 | red |

SHASHIKANT CHAUBEY 2000300100207


| 22 | red |
| 31 | red |
| 31 | red |
| 64 | red |
+-----+-------+
rows in set (0.00 sec)

Q3. Find the color of boats reserved by Dustin


mysql> select sname, color from sailor
-> join reserve
-> on reserve.Sid = sailor.Sid
-> join boat b
-> on b.Bid = reserve.bid
-> where sname = 'Dustin';
+--------+-------+
| sname | color |
+--------+-------+
| Dustin | blue |
| Dustin | red |
| Dustin | green |
| Dustin | red |
+--------+-------+
4 rows in set (0.00 sec)

Q4. Find sid of sailors who have reserved red or green boats.

mysql> select sname,bname, color from sailor


-> join reserve
-> on reserve.Sid = sailor.Sid

SHASHIKANT CHAUBEY 2000300100207


-> join boat b
-> on b.Bid = reserve.bid
-> where sname = 'Dustin'
-> ;
+--------+-----------+-------+
| sname | bname | color |
+--------+-----------+-------+
| Dustin | interlake | blue |
| Dustin | interlake | red |
| Dustin | clipper | green |
| Dustin | marine | red |
+--------+-----------+-------+
5 rows in set (0.00 sec)

Q5. Find sailors name who have reserved red or green boats.

mysql> select sailor.sid,bname, color from sailor


-> join reserve
-> on reserve.Sid = sailor.Sid
-> join boat b
-> on b.Bid = reserve.bid
-> where color = 'red' or color = 'green';

+-----+-----------+-------+
| sid | bname | color |
+-----+-----------+-------+
| 22 | interlake | red |
| 22 | clipper | green |
| 22 | marine | red |

SHASHIKANT CHAUBEY 2000300100207


| 31 | interlake | red |
| 31 | clipper | green |
| 31 | marine | red |
| 64 | interlake | red |
| 74 | clipper | green |
+-----+-----------+-------+
8 rows in set (0.00 sec)

Q6 . Find sailors name who have reserved red AND green boats.

mysql> select sname,bname, color from sailor


-> join reserve
-> on reserve.Sid = sailor.Sid
-> join boat b
-> on b.Bid = reserve.bid
-> where color = 'red' and color = 'green';
Empty set (0.00 sec)

Q7. Find the sids of all sailor's who have reserved red boats but not green
boats.

mysql> select sailor.sid,bname, color from sailor


-> join reserve
-> on reserve.Sid = sailor.Sid
-> join boat b
-> on b.Bid = reserve.bid

SHASHIKANT CHAUBEY 2000300100207


-> where color = 'red' and not color = 'green';
+-----+-----------+-------+
| sid | bname | color |
+-----+-----------+-------+
| 22 | interlake | red |
| 22 | marine | red |
| 31 | interlake | red |
| 31 | marine | red |
| 64 | interlake | red |
+-----+-----------+-------+
5 rows in set (0.04 sec)

SHASHIKANT CHAUBEY 2000300100207

You might also like