SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
Practical No: 3
Problem Statement: Design at least 10 SQL queries for suitable database
application using SQL DML statements:
Insert, Select, Update, Delete with operators, functions, and set operator.
mysql> use prac3;
Database changed
mysql> DROP TABLE IF EXISTS emp;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
mysql> CREATE TABLE emp (
-> empno decimal(4,0) NOT NULL,
-> ename varchar(10) default NULL,
-> job varchar(9) default NULL,
-> mgr decimal(4,0) default NULL,
-> hiredate date default NULL,
-> sal decimal(7,2) default NULL,
-> comm decimal(7,2) default NULL,
-> deptno decimal(2,0) default NULL
-> );
Query OK, 0 rows affected (0.06 sec)
mysql>
mysql> DROP TABLE IF EXISTS dept;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
mysql> CREATE TABLE dept (
-> deptno decimal(2,0) default NULL,
-> dname varchar(14) default NULL,
-> loc varchar(13) default NULL
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> INSERT INTO emp VALUES ('7369','SMITH','CLERK','7902','1980-12-
17','800.00',NULL,'20');
Query OK, 1 row affected (0.02 sec)
mysql> INSERT INTO emp VALUES ('7499','ALLEN','SALESMAN','7698','1981-02-
20','1600.00','300.00','30');
Query OK, 1 row affected (0.04 sec)
mysql> INSERT INTO emp VALUES ('7521','WARD','SALESMAN','7698','1981-02-
22','1250.00','500.00','30');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO emp VALUES ('7566','JONES','MANAGER','7839','1981-04-
02','2975.00',NULL,'20');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO emp VALUES ('7654','MARTIN','SALESMAN','7698','1981-09-
28','1250.00','1400.00','30');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO emp VALUES ('7698','BLAKE','MANAGER','7839','1981-05-
01','2850.00',NULL,'30');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO emp VALUES ('7782','CLARK','MANAGER','7839','1981-06-
09','2450.00',NULL,'10');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO emp VALUES ('7788','SCOTT','ANALYST','7566','1982-12-
09','3000.00',NULL,'20');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO emp VALUES ('7839','KING','PRESIDENT',NULL,'1981-11-
17','5000.00',NULL,'10');
Query OK, 1 row affected (0.00 sec)
mysql> select ename, sal frommysql> select ename, sal from emp where sal between
1000 and 5000;
+--------+---------+
| ename | sal |
+--------+---------+
| ALLEN | 1600.00 |
| WARD | 1250.00 |
| JONES | 2975.00 |
| MARTIN | 1250.00 |
| BLAKE | 2850.00 |
| CLARK | 2450.00 |
| SCOTT | 3000.00 |
| KING | 5000.00 |
| TURNER | 1500.00 |
| ADAMS | 1100.00 |
| FORD | 3000.00 |
| MILLER | 1300.00 |
+--------+---------+
12 rows in set (0.00 sec)
emp where sal between 1000 and 5000;
+--------+---------+
| ename | sal |
+--------+---------+
| ALLEN | 1600.00 |
| WARD | 1250.00 |
| JONES | 2975.00 |
| MARTIN | 1250.00 |
| BLAKE | 2850.00 |
| CLARK | 2450.00 |
| SCOTT | 3000.00 |
| KING | 5000.00 |
| TURNER | 1500.00 |
| ADAMS | 1100.00 |
| FORD | 3000.00 |
| MILLER | 1300.00 |
+--------+---------+
12 rows in set (0.00 sec)
mysql> INSERT INTO emp VALUES ('7844','TURNER','SALESMAN','7698','1981-09-
08','1500.00','0.00','30');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO emp VALUES ('7876','ADAMS','CLERK','7788','1983-01-
12','1100.00',NULL,'20');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO emp VALUES ('7900','JAMES','CLERK','7698','1981-12-
03','950.00',NULL,'30');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO emp VALUES ('7902','FORD','ANALYST','7566','1981-12-
03','3000.00',NULL,'20');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO emp VALUES ('7934','MILLER','CLERK','7782','1982-01-
23','1300.00',NULL,'10');
Query OK, 1 row affected (0.01 sec)
mysql>
mysql> INSERT INTO dept VALUES ('10','ACCOUNTING','NEW YORK');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO dept VALUES ('20','RESEARCH','DALLAS');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO dept VALUES ('30','SALES','CHICAGO');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO dept VALUES ('40','OPERATIONS','BOSTON');
Query OK, 1 row affected (0.00 sec)
mysql> desc emp;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| empno | decimal(4,0) | NO | | NULL | |
| ename | varchar(10) | YES | | NULL | |
| job | varchar(9) | YES | | NULL | |
| mgr | decimal(4,0) | YES | | NULL | |
| hiredate | date | YES | | NULL | |
| sal | decimal(7,2) | YES | | NULL | |
| comm | decimal(7,2) | YES | | NULL | |
| deptno | decimal(2,0) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
8 rows in set (0.00 sec)
mysql> select * from emp;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)
mysql> select distinct(job) from emp;
+-----------+
| job |
+-----------+mysql> select ename, sal from emp where sal between 1000 and 5000;
+--------+---------+
| ename | sal |
+--------+---------+
| ALLEN | 1600.00 |
| WARD | 1250.00 |
| JONES | 2975.00 |
| MARTIN | 1250.00 |
| BLAKE | 2850.00 |
| CLARK | 2450.00 |
| SCOTT | 3000.00 |
| KING | 5000.00 |
| TURNER | 1500.00 |
| ADAMS | 1100.00 |
| FORD | 3000.00 |
| MILLER | 1300.00 |
+--------+---------+
12 rows in set (0.00 sec)
| CLERK |
| SALESMAN |
| MANAGER |
| ANALYST |
| PRESIDENT |
+-----------+
5 rows in set (0.00 sec)
mysql> select empno,ename,sal from emp where deptno=20 ;
+-------+-------+---------+
| empno | ename | sal |
+-------+-------+---------+
| 7369 | SMITH | 800.00 |
| 7566 | JONES | 2975.00 |
| 7788 | SCOTT | 3000.00 |
| 7876 | ADAMS | 1100.00 |
| 7902 | FORD | 3000.00 |
+-------+-------+---------+
5 rows in set (0.00 sec)
mysql> select empno,ename,sal from emp where deptno like 20 ;
+-------+-------+---------+
| empno | ename | sal |
+-------+-------+---------+
| 7369 | SMITH | 800.00 |
| 7566 | JONES | 2975.00 |
| 7788 | SCOTT | 3000.00 |
| 7876 | ADAMS | 1100.00 |
| 7902 | FORD | 3000.00 |
+-------+-------+---------+
5 rows in set (0.00 sec)
mysql> select empno,ename,sal from emp where ename like 'a%' ;
+-------+-------+---------+
| empno | ename | sal |
+-------+-------+---------+
| 7499 | ALLEN | 1600.00 |
| 7876 | ADAMS | 1100.00 |
+-------+-------+---------+
2 rows in set (0.00 sec)
mysql> select * from emp where ename like '__N%';
+-------+-------+-----------+------+------------+---------+------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+-------+-----------+------+------------+---------+------+--------+
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
+-------+-------+-----------+------+------------+---------+------+--------+
2 rows in set (0.00 sec)
mysql> select deptno as DEPTNO, MAX(sal) as "MAXIMUM SALARY" from emp group by
(deptno);
+--------+----------------+
| DEPTNO | MAXIMUM SALARY |
+--------+----------------+
| 10 | 5000.00 |
| 20 | 3000.00 |
| 30 | 2850.00 |
+--------+----------------+
3 rows in set (0.00 sec)
mysql> select count(sal) from emp where sal=3000;
+------------+
| count(sal) |
+------------+
| 2 |
+------------+
1 row in set (0.00 sec)
mysql> select MAX(sal) from emp;
+----------+
| MAX(sal) |
+----------+
| 5000.00 |
+----------+
1 row in set (0.00 sec)
mysql> select MIN(sal) from emp;
+----------+
| MIN(sal) |
+----------+
| 800.00 |
+----------+
1 row in set (0.00 sec)
mysql> select MIN(sal) least, MAX(sal) max from emp;
+--------+---------+
| least | max |
+--------+---------+
| 800.00 | 5000.00 |
+--------+---------+
1 row in set (0.00 sec)
mysql> select deptno , MIN(sal) "MINIMUM SALARY" from emp group by (deptno);
+--------+----------------+
| deptno | MINIMUM SALARY |
+--------+----------------+
| 10 | 1300.00 |
| 20 | 800.00 |
| 30 | 950.00 |
+--------+----------------+
3 rows in set (0.00 sec)
mysql> select SUM(sal) totalsal from emp;
+----------+
| totalsal |
+----------+
| 29025.00 |
+----------+
1 row in set (0.00 sec)
mysql> select deptno , SUM(sal) "sal sum" from emp group by (deptno);
+--------+----------+
| deptno | sal sum |
+--------+----------+
| 10 | 8750.00mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
|
| 20 | 10875.00 |
| 30 | 9400.00 |
+--------+----------+
3 rows in set (0.00 sec)
mysql> select deptno , avg(sal) "sal avg" from emp group by (deptno);
+--------+-------------+
| deptno | sal avg |
+--------+-------------+
| 10 | 2916.666667 |
| 20 | 2175.000000 |
| 30 | 1566.666667 |
+--------+-------------+
3 rows in set (0.00 sec)
mysql> select * from emp where job in('CLERK','PRESIDENT');
+-------+--------+-----------+------+------------+---------+------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+------+--------+
5 rows in set (0.00 sec)
mysql> select * from emp where job not in('CLERK','PRESIDENT');
+-------+--------+----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+----------+------+------------+---------+---------+--------+
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
+-------+--------+----------+------+------------+---------+---------+--------+
9 rows in set (0.00 sec)
mysql> select * fromysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
m emp order by comm;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7782 | CLARK |
mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
+-------+--------+-
mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)
mysql> select * from emp where comm <> 'NULL';
+-------+--------+----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+----------+------+------------+---------+---------+--------+
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
+-------+--------+----------+------+------------+---------+---------+--------+
3 rows in set, 1 warning (0.00 sec)
mysql> select * from emp where comm <> 'NULL' order by comm desc;
+-------+--------+----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+----------+------+------------+---------+---------+--------+
| 7654 | MARTIN | mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
sec)
SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
+-------+--------+----------+------+------------+---------+---------+--------+
3 rows in set, 1 warning (0.00 sec)
mysql> select ename, sal from emp where sal between 1000 and 5000;
+--------+---------+mysql> select ename, sal from emp where sal between 1000 and
5000;
+--------+---------+
| ename | sal |
+--------+---------+
| ALLEN | 1600.00 |
| WARD | 1250.00
mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
|
| JONES | 2975.00 |
| MARTIN | 1250.00 mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
|
| BLAKE | 2850.00 |
| CLARK | 2450.00 |
| SCOTT | 3000.00 |
| KING | 5000.00 |
| TURNER | 1500.00 |
| ADAMS | 1100.00 |
| FORD | 3000.00 |
| MILLER | 1300.00 |
+--------+---------+
12 rows in set (0.00 sec)
| ename | sal |
+--------+---------+
| ALLEN | 1600.00 |
| WARD | 1250.00 |
| JONES | 2975.00 |
| MARTIN | 1250.00 |
| BLAKE | 2850.00 |
| CLARK | 2450.00 |
| SCOTT | 3000.00 |
| KING | 5000.00 |
| TURNER | 1500.00 |
| ADAMS | 1100.00 |
| FORD | 3000.00 |
| MILLER | 1300.00 |
+--------+---------+
12 rows in set (0.00 sec)
mysql> select empno,ename,job,comm,sal from emp where sal>=1000 and sal<=3000;
+-------+--------+----------+---------+---------+
| empno | ename | job | comm | sal |
+-------+--------+----------+---------+---------+
| 7499 | ALLEN | SALESMAN | 300.00 | 1600.00 |
| 7521 | WARD | SALESMAN | 500.00 | 1250.00 |
| 7566 | JONES | MANAGER | NULL | 2975.00 |
| 7654 | MARTIN | SALESMAN | 1400.00 | 1250.00 |
| 7698 | BLAKE | MANAGER | NULL | 2850.00 |
| 7782 | CLARK | MANAGER | NULL | 2450.00 |
| 7788 | SCOTT | ANALYST | NULL | 3000.00 |
| 7844 | TURNER | SALESMAN | 0.00 | 1500.00 |
| 7876 | ADAMS | CLERK | NULL | 1100.00 |
| 7902 | FORD | ANALYST | NULL | 3000.00 |
| 7934 | MILLER | CLERK | NULL | 1300.00 |
+-------+--------+----------+---------+---------+
11 rows in set (0.00 sec)
mysql> select empno,ename,job,comm,sal from emp where sal>=1000 or sal<=3000;
+-------+--------+-----------+---------+---------+
| empno | ename | job | comm | sal |
+-------+--------+-----------+---------+---------+
| 7369 | SMITH | CLERK | NULL | 800.00 |
| 7499 | ALLEN | SALESMAN | 300.00 | 1600.00 |
| 7521 | WARD | SALESMAN | 500.00 | 1250.00 |
| 7566 | JONES | MANAGER | NULL | 2975.00 |
| 7654 | MARTIN | SALESMAN | 1400.00 | 1250.00 |
| 7698 | BLAKE | MANAGER | NULL | 2850.00 |
| 7782 | CLARK | MANAGER | NULL | 2450.00 |
| 7788 | SCOTT | ANALYST | NULL | 3000.00 |
| 7839 | KING | PRESIDENT | NULL | 5000.00 |
| 7844 | TURNER | SALESMAN | 0.00 | 1500.00 |
| 7876 | ADAMS | CLERK | NULL | 1100.00 |
| 7900 | JAMES | CLERK | NULL | 950.00 |
| 7902 | FORD | ANALYST | NULL | 3000.00 |
| 7934 | MILLER | CLERK | NULL | 1300.00 |
+-------+--------+-----------+---------+---------+
14 rows in set (0.00 sec)
mysql> select empno,ename,job,comm,sal from emp where not sal=3000;
+-------+--------+-----------+---------+---------+
| empno | ename | job | comm | sal |
+-------+--------+-----------+---------+---------+
| 7369 | SMITH | CLERK | NULL | 800.00 |
| 7499 | ALLEN | SALESMAN | 300.00 | 1600.00 |
| 7521 | WARD | SALESMAN | 500.00 | 1250.00 |
| 7566 | JONES | MANAGER | NULL | 2975.00 |
| 7654 | MARTIN | SALESMAN | 1400.00 | 1250.00 |
| 7698 | BLAKE | MANAGER | NULL | 2850.00 |
| 7782 | CLARK | MANAGER | NULL | 2450.00 |
| 7839 | KING | PRESIDENT | NULL | 5000.00 |
| 7844 | TURNER | SALESMAN | 0.00 | 1500.00 |
| 7876 | ADAMS | CLERK | NULL | 1100.00 |
| 7900 | JAMES | CLERK | NULL | 950.00 |
| 7934 | MILLER | CLERK | NULL | 1300.00 |
+-------+--------+-----------+---------+---------+
12 rows in set (0.00 sec)
mysql> update emp set comm=520 where empno=7369;
Query OK, 1 row affected (0.37 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from emp;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | 520.00 | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)
mysql> delete from emp where empno=7369;
Query OK, 1 row affected (0.01 sec)
mysql> select * from emp;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hiredate | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
13 rows in set (0.00 sec)
________________________________________________________________________________
_______
mysql> select * from t1;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
5 rows in set (0.00 sec)
mysql> select * from t1 union select * from t2;
+-----+-------+
| Rno | Name |
+-----+-------+
| 1 | amit |
| 2 | rohan |
| 3 | rahul |
| 4 | Nayan |
| 5 | pati |
| 6 | xyz |
| 7 | pqr |
+-----+-------+
7 rows in set (0.00 sec)
mysql> select distinct(Rno) as "Common RollNo" from t1 inner join t2
using(Rno);
+---------------+
| Common RollNo |
+---------------+
| 3 |
| 4 |
| 5 |
+---------------+
3 rows in set (0.00 sec)

Más contenido relacionado

La actualidad más candente

Getweeklyhoursbyuser
GetweeklyhoursbyuserGetweeklyhoursbyuser
Getweeklyhoursbyuserhasheemm
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse2013901097
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and boundAbhishek Singh
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmHoneyChintal
 
Dynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain MultiplicationDynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain MultiplicationPecha Inc.
 
Knapsack problem using dynamic programming
Knapsack problem using dynamic programmingKnapsack problem using dynamic programming
Knapsack problem using dynamic programmingkhush_boo31
 
Testing Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnitTesting Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnitEric Wendelin
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Mohanlal Sukhadia University (MLSU)
 
Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Sanjay Pathak
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examplesmua99
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsDrishti Bhalla
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.bhavesh lande
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123Ankita Goyal
 
Fuzzy Set Theory
Fuzzy Set TheoryFuzzy Set Theory
Fuzzy Set TheoryAMIT KUMAR
 
Birch Algorithm With Solved Example
Birch Algorithm With Solved ExampleBirch Algorithm With Solved Example
Birch Algorithm With Solved Examplekailash shaw
 

La actualidad más candente (20)

Getweeklyhoursbyuser
GetweeklyhoursbyuserGetweeklyhoursbyuser
Getweeklyhoursbyuser
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse
 
Chess engine presentation
Chess engine presentationChess engine presentation
Chess engine presentation
 
BIGDATA ANALYTICS LAB MANUAL final.pdf
BIGDATA  ANALYTICS LAB MANUAL final.pdfBIGDATA  ANALYTICS LAB MANUAL final.pdf
BIGDATA ANALYTICS LAB MANUAL final.pdf
 
0 1 knapsack using branch and bound
0 1 knapsack using branch and bound0 1 knapsack using branch and bound
0 1 knapsack using branch and bound
 
Knapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithmKnapsack problem algorithm, greedy algorithm
Knapsack problem algorithm, greedy algorithm
 
Dynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain MultiplicationDynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain Multiplication
 
Knapsack problem using dynamic programming
Knapsack problem using dynamic programmingKnapsack problem using dynamic programming
Knapsack problem using dynamic programming
 
Testing Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnitTesting Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnit
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)Assignment 2 (16-08-2013)
Assignment 2 (16-08-2013)
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.aggregation and indexing with suitable example using MongoDB.
aggregation and indexing with suitable example using MongoDB.
 
Map Reduce
Map ReduceMap Reduce
Map Reduce
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
 
Fuzzy Set Theory
Fuzzy Set TheoryFuzzy Set Theory
Fuzzy Set Theory
 
Birch Algorithm With Solved Example
Birch Algorithm With Solved ExampleBirch Algorithm With Solved Example
Birch Algorithm With Solved Example
 
DBMS Practical File
DBMS Practical FileDBMS Practical File
DBMS Practical File
 

Similar a database application using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set operator.

Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQLConnor McDonald
 
Statements project 2
Statements project 2Statements project 2
Statements project 2AlexisHarvey8
 
Perth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL TechniquesPerth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL TechniquesConnor McDonald
 
Mysqlfunctions
MysqlfunctionsMysqlfunctions
MysqlfunctionsN13M
 
Sangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLSangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLConnor McDonald
 
Analytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hiveAnalytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hiveAnkit Beohar
 
MySQL5.7で遊んでみよう
MySQL5.7で遊んでみようMySQL5.7で遊んでみよう
MySQL5.7で遊んでみようyoku0825
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with outputNexus
 
SQL techniques for faster applications
SQL techniques for faster applicationsSQL techniques for faster applications
SQL techniques for faster applicationsConnor McDonald
 
Optimizing Queries Using Window Functions
Optimizing Queries Using Window FunctionsOptimizing Queries Using Window Functions
Optimizing Queries Using Window FunctionsI Goo Lee
 
ILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for DevelopersILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for DevelopersConnor McDonald
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql featuresConnor McDonald
 

Similar a database application using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set operator. (20)

Mysql and html
Mysql and html Mysql and html
Mysql and html
 
Empresa completo
Empresa completoEmpresa completo
Empresa completo
 
Sangam 19 - Analytic SQL
Sangam 19 - Analytic SQLSangam 19 - Analytic SQL
Sangam 19 - Analytic SQL
 
Analytic SQL Sep 2013
Analytic SQL Sep 2013Analytic SQL Sep 2013
Analytic SQL Sep 2013
 
Statements project 2
Statements project 2Statements project 2
Statements project 2
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
 
Perth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL TechniquesPerth APAC Groundbreakers tour - SQL Techniques
Perth APAC Groundbreakers tour - SQL Techniques
 
Mysqlfunctions
MysqlfunctionsMysqlfunctions
Mysqlfunctions
 
Sangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQLSangam 18 - Great Applications with Great SQL
Sangam 18 - Great Applications with Great SQL
 
Cube rollup slides
Cube rollup slidesCube rollup slides
Cube rollup slides
 
Analytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hiveAnalytics functions in mysql, oracle and hive
Analytics functions in mysql, oracle and hive
 
MySQL5.7で遊んでみよう
MySQL5.7で遊んでみようMySQL5.7で遊んでみよう
MySQL5.7で遊んでみよう
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with output
 
KScope19 - SQL Features
KScope19 - SQL FeaturesKScope19 - SQL Features
KScope19 - SQL Features
 
SQL techniques for faster applications
SQL techniques for faster applicationsSQL techniques for faster applications
SQL techniques for faster applications
 
Optimizing Queries Using Window Functions
Optimizing Queries Using Window FunctionsOptimizing Queries Using Window Functions
Optimizing Queries Using Window Functions
 
Cassandra & Maria DB
Cassandra & Maria DBCassandra & Maria DB
Cassandra & Maria DB
 
Tugas praktikum smbd
Tugas praktikum smbdTugas praktikum smbd
Tugas praktikum smbd
 
ILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for DevelopersILOUG 2019 - SQL features for Developers
ILOUG 2019 - SQL features for Developers
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 

Más de bhavesh lande

The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019 The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019 bhavesh lande
 
information control and Security system
information control and Security systeminformation control and Security system
information control and Security systembhavesh lande
 
information technology and infrastructures choices
information technology and  infrastructures choicesinformation technology and  infrastructures choices
information technology and infrastructures choicesbhavesh lande
 
ethical issues,social issues
 ethical issues,social issues ethical issues,social issues
ethical issues,social issuesbhavesh lande
 
managing inforamation system
managing inforamation systemmanaging inforamation system
managing inforamation systembhavesh lande
 
• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governancebhavesh lande
 
organisations and information systems
organisations and  information systemsorganisations and  information systems
organisations and information systemsbhavesh lande
 
IT stratergy and digital goods
IT stratergy and digital goodsIT stratergy and digital goods
IT stratergy and digital goodsbhavesh lande
 
Implement Mapreduce with suitable example using MongoDB.
 Implement Mapreduce with suitable example using MongoDB. Implement Mapreduce with suitable example using MongoDB.
Implement Mapreduce with suitable example using MongoDB.bhavesh lande
 
applications and advantages of python
applications and advantages of pythonapplications and advantages of python
applications and advantages of pythonbhavesh lande
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data sciencebhavesh lande
 
data scientists and their role
data scientists and their roledata scientists and their role
data scientists and their rolebhavesh lande
 
statistics techniques to deal with data
statistics techniques to deal with datastatistics techniques to deal with data
statistics techniques to deal with databhavesh lande
 
introduction to data science
introduction to data scienceintroduction to data science
introduction to data sciencebhavesh lande
 

Más de bhavesh lande (18)

The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019 The Annual G20 Scorecard – Research Performance 2019
The Annual G20 Scorecard – Research Performance 2019
 
information control and Security system
information control and Security systeminformation control and Security system
information control and Security system
 
information technology and infrastructures choices
information technology and  infrastructures choicesinformation technology and  infrastructures choices
information technology and infrastructures choices
 
ethical issues,social issues
 ethical issues,social issues ethical issues,social issues
ethical issues,social issues
 
managing inforamation system
managing inforamation systemmanaging inforamation system
managing inforamation system
 
• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance• E-commerce, e-business ,e-governance
• E-commerce, e-business ,e-governance
 
IT and innovations
 IT and  innovations  IT and  innovations
IT and innovations
 
organisations and information systems
organisations and  information systemsorganisations and  information systems
organisations and information systems
 
IT stratergy and digital goods
IT stratergy and digital goodsIT stratergy and digital goods
IT stratergy and digital goods
 
Implement Mapreduce with suitable example using MongoDB.
 Implement Mapreduce with suitable example using MongoDB. Implement Mapreduce with suitable example using MongoDB.
Implement Mapreduce with suitable example using MongoDB.
 
working with python
working with pythonworking with python
working with python
 
applications and advantages of python
applications and advantages of pythonapplications and advantages of python
applications and advantages of python
 
introduction of python in data science
introduction of python in data scienceintroduction of python in data science
introduction of python in data science
 
tools
toolstools
tools
 
data scientists and their role
data scientists and their roledata scientists and their role
data scientists and their role
 
applications
applicationsapplications
applications
 
statistics techniques to deal with data
statistics techniques to deal with datastatistics techniques to deal with data
statistics techniques to deal with data
 
introduction to data science
introduction to data scienceintroduction to data science
introduction to data science
 

Último

GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxNadaHaitham1
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 

Último (20)

GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 

database application using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set operator.

  • 1. Practical No: 3 Problem Statement: Design at least 10 SQL queries for suitable database application using SQL DML statements: Insert, Select, Update, Delete with operators, functions, and set operator. mysql> use prac3; Database changed mysql> DROP TABLE IF EXISTS emp; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> mysql> CREATE TABLE emp ( -> empno decimal(4,0) NOT NULL, -> ename varchar(10) default NULL, -> job varchar(9) default NULL, -> mgr decimal(4,0) default NULL, -> hiredate date default NULL, -> sal decimal(7,2) default NULL, -> comm decimal(7,2) default NULL, -> deptno decimal(2,0) default NULL -> ); Query OK, 0 rows affected (0.06 sec) mysql> mysql> DROP TABLE IF EXISTS dept; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> mysql> CREATE TABLE dept ( -> deptno decimal(2,0) default NULL, -> dname varchar(14) default NULL, -> loc varchar(13) default NULL -> ); Query OK, 0 rows affected (0.01 sec) mysql> mysql> INSERT INTO emp VALUES ('7369','SMITH','CLERK','7902','1980-12- 17','800.00',NULL,'20'); Query OK, 1 row affected (0.02 sec) mysql> INSERT INTO emp VALUES ('7499','ALLEN','SALESMAN','7698','1981-02- 20','1600.00','300.00','30'); Query OK, 1 row affected (0.04 sec) mysql> INSERT INTO emp VALUES ('7521','WARD','SALESMAN','7698','1981-02- 22','1250.00','500.00','30'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO emp VALUES ('7566','JONES','MANAGER','7839','1981-04- 02','2975.00',NULL,'20'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO emp VALUES ('7654','MARTIN','SALESMAN','7698','1981-09- 28','1250.00','1400.00','30'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO emp VALUES ('7698','BLAKE','MANAGER','7839','1981-05- 01','2850.00',NULL,'30'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO emp VALUES ('7782','CLARK','MANAGER','7839','1981-06- 09','2450.00',NULL,'10'); Query OK, 1 row affected (0.01 sec)
  • 2. mysql> INSERT INTO emp VALUES ('7788','SCOTT','ANALYST','7566','1982-12- 09','3000.00',NULL,'20'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO emp VALUES ('7839','KING','PRESIDENT',NULL,'1981-11- 17','5000.00',NULL,'10'); Query OK, 1 row affected (0.00 sec) mysql> select ename, sal frommysql> select ename, sal from emp where sal between 1000 and 5000; +--------+---------+ | ename | sal | +--------+---------+ | ALLEN | 1600.00 | | WARD | 1250.00 | | JONES | 2975.00 | | MARTIN | 1250.00 | | BLAKE | 2850.00 | | CLARK | 2450.00 | | SCOTT | 3000.00 | | KING | 5000.00 | | TURNER | 1500.00 | | ADAMS | 1100.00 | | FORD | 3000.00 | | MILLER | 1300.00 | +--------+---------+ 12 rows in set (0.00 sec) emp where sal between 1000 and 5000; +--------+---------+ | ename | sal | +--------+---------+ | ALLEN | 1600.00 | | WARD | 1250.00 | | JONES | 2975.00 | | MARTIN | 1250.00 | | BLAKE | 2850.00 | | CLARK | 2450.00 | | SCOTT | 3000.00 | | KING | 5000.00 | | TURNER | 1500.00 | | ADAMS | 1100.00 | | FORD | 3000.00 | | MILLER | 1300.00 | +--------+---------+ 12 rows in set (0.00 sec) mysql> INSERT INTO emp VALUES ('7844','TURNER','SALESMAN','7698','1981-09- 08','1500.00','0.00','30'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO emp VALUES ('7876','ADAMS','CLERK','7788','1983-01- 12','1100.00',NULL,'20'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO emp VALUES ('7900','JAMES','CLERK','7698','1981-12- 03','950.00',NULL,'30'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO emp VALUES ('7902','FORD','ANALYST','7566','1981-12- 03','3000.00',NULL,'20'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO emp VALUES ('7934','MILLER','CLERK','7782','1982-01- 23','1300.00',NULL,'10');
  • 3. Query OK, 1 row affected (0.01 sec) mysql> mysql> INSERT INTO dept VALUES ('10','ACCOUNTING','NEW YORK'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO dept VALUES ('20','RESEARCH','DALLAS'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO dept VALUES ('30','SALES','CHICAGO'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO dept VALUES ('40','OPERATIONS','BOSTON'); Query OK, 1 row affected (0.00 sec) mysql> desc emp; +----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | empno | decimal(4,0) | NO | | NULL | | | ename | varchar(10) | YES | | NULL | | | job | varchar(9) | YES | | NULL | | | mgr | decimal(4,0) | YES | | NULL | | | hiredate | date | YES | | NULL | | | sal | decimal(7,2) | YES | | NULL | | | comm | decimal(7,2) | YES | | NULL | | | deptno | decimal(2,0) | YES | | NULL | | +----------+--------------+------+-----+---------+-------+ 8 rows in set (0.00 sec) mysql> select * from emp; +-------+--------+-----------+------+------------+---------+---------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+-----------+------+------------+---------+---------+--------+ | 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 | | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | | 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 | | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 | | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 | | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 | | 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 | | 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 | | 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 | | 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 | +-------+--------+-----------+------+------------+---------+---------+--------+ 14 rows in set (0.00 sec) mysql> select distinct(job) from emp; +-----------+ | job | +-----------+mysql> select ename, sal from emp where sal between 1000 and 5000; +--------+---------+ | ename | sal | +--------+---------+ | ALLEN | 1600.00 | | WARD | 1250.00 | | JONES | 2975.00 | | MARTIN | 1250.00 | | BLAKE | 2850.00 | | CLARK | 2450.00 |
  • 4. | SCOTT | 3000.00 | | KING | 5000.00 | | TURNER | 1500.00 | | ADAMS | 1100.00 | | FORD | 3000.00 | | MILLER | 1300.00 | +--------+---------+ 12 rows in set (0.00 sec) | CLERK | | SALESMAN | | MANAGER | | ANALYST | | PRESIDENT | +-----------+ 5 rows in set (0.00 sec) mysql> select empno,ename,sal from emp where deptno=20 ; +-------+-------+---------+ | empno | ename | sal | +-------+-------+---------+ | 7369 | SMITH | 800.00 | | 7566 | JONES | 2975.00 | | 7788 | SCOTT | 3000.00 | | 7876 | ADAMS | 1100.00 | | 7902 | FORD | 3000.00 | +-------+-------+---------+ 5 rows in set (0.00 sec) mysql> select empno,ename,sal from emp where deptno like 20 ; +-------+-------+---------+ | empno | ename | sal | +-------+-------+---------+ | 7369 | SMITH | 800.00 | | 7566 | JONES | 2975.00 | | 7788 | SCOTT | 3000.00 | | 7876 | ADAMS | 1100.00 | | 7902 | FORD | 3000.00 | +-------+-------+---------+ 5 rows in set (0.00 sec) mysql> select empno,ename,sal from emp where ename like 'a%' ; +-------+-------+---------+ | empno | ename | sal | +-------+-------+---------+ | 7499 | ALLEN | 1600.00 | | 7876 | ADAMS | 1100.00 | +-------+-------+---------+ 2 rows in set (0.00 sec) mysql> select * from emp where ename like '__N%'; +-------+-------+-----------+------+------------+---------+------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+-------+-----------+------+------------+---------+------+--------+ | 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 | +-------+-------+-----------+------+------------+---------+------+--------+ 2 rows in set (0.00 sec) mysql> select deptno as DEPTNO, MAX(sal) as "MAXIMUM SALARY" from emp group by (deptno); +--------+----------------+ | DEPTNO | MAXIMUM SALARY |
  • 5. +--------+----------------+ | 10 | 5000.00 | | 20 | 3000.00 | | 30 | 2850.00 | +--------+----------------+ 3 rows in set (0.00 sec) mysql> select count(sal) from emp where sal=3000; +------------+ | count(sal) | +------------+ | 2 | +------------+ 1 row in set (0.00 sec) mysql> select MAX(sal) from emp; +----------+ | MAX(sal) | +----------+ | 5000.00 | +----------+ 1 row in set (0.00 sec) mysql> select MIN(sal) from emp; +----------+ | MIN(sal) | +----------+ | 800.00 | +----------+ 1 row in set (0.00 sec) mysql> select MIN(sal) least, MAX(sal) max from emp; +--------+---------+ | least | max | +--------+---------+ | 800.00 | 5000.00 | +--------+---------+ 1 row in set (0.00 sec) mysql> select deptno , MIN(sal) "MINIMUM SALARY" from emp group by (deptno); +--------+----------------+ | deptno | MINIMUM SALARY | +--------+----------------+ | 10 | 1300.00 | | 20 | 800.00 | | 30 | 950.00 | +--------+----------------+ 3 rows in set (0.00 sec) mysql> select SUM(sal) totalsal from emp; +----------+ | totalsal | +----------+ | 29025.00 | +----------+ 1 row in set (0.00 sec) mysql> select deptno , SUM(sal) "sal sum" from emp group by (deptno); +--------+----------+ | deptno | sal sum | +--------+----------+ | 10 | 8750.00mysql> select * from t1; +-----+-------+
  • 6. | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) | | 20 | 10875.00 | | 30 | 9400.00 | +--------+----------+ 3 rows in set (0.00 sec) mysql> select deptno , avg(sal) "sal avg" from emp group by (deptno); +--------+-------------+ | deptno | sal avg | +--------+-------------+ | 10 | 2916.666667 | | 20 | 2175.000000 | | 30 | 1566.666667 | +--------+-------------+ 3 rows in set (0.00 sec) mysql> select * from emp where job in('CLERK','PRESIDENT'); +-------+--------+-----------+------+------------+---------+------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+-----------+------+------------+---------+------+--------+ | 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 | | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 | | 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 | | 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 | +-------+--------+-----------+------+------------+---------+------+--------+ 5 rows in set (0.00 sec) mysql> select * from emp where job not in('CLERK','PRESIDENT'); +-------+--------+----------+------+------------+---------+---------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+----------+------+------------+---------+---------+--------+ | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | | 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 | | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 | | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 | | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 | | 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | | 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 | +-------+--------+----------+------+------------+---------+---------+--------+
  • 7. 9 rows in set (0.00 sec) mysql> select * fromysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) m emp order by comm; +-------+--------+-----------+------+------------+---------+---------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+-----------+------+------------+---------+---------+--------+ | 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 | | 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 | | 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 | | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 | | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 | | 7782 | CLARK | mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2;
  • 8. +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 | | 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 | | 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 | | 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | +-------+--------+- mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) | 5 | pati | +-----+-------+
  • 9. 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) ----------+------+------------+---------+---------+--------+ 14 rows in set (0.00 sec) mysql> select * from emp where comm <> 'NULL'; +-------+--------+----------+------+------------+---------+---------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+----------+------+------------+---------+---------+--------+ | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | +-------+--------+----------+------+------------+---------+---------+--------+ 3 rows in set, 1 warning (0.00 sec) mysql> select * from emp where comm <> 'NULL' order by comm desc; +-------+--------+----------+------+------------+---------+---------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+----------+------+------------+---------+---------+--------+ | 7654 | MARTIN | mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec)
  • 10. mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) sec) SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | +-------+--------+----------+------+------------+---------+---------+--------+ 3 rows in set, 1 warning (0.00 sec) mysql> select ename, sal from emp where sal between 1000 and 5000; +--------+---------+mysql> select ename, sal from emp where sal between 1000 and 5000; +--------+---------+ | ename | sal | +--------+---------+ | ALLEN | 1600.00 | | WARD | 1250.00 mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+
  • 11. | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) | | JONES | 2975.00 | | MARTIN | 1250.00 mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) | | BLAKE | 2850.00 | | CLARK | 2450.00 | | SCOTT | 3000.00 | | KING | 5000.00 |
  • 12. | TURNER | 1500.00 | | ADAMS | 1100.00 | | FORD | 3000.00 | | MILLER | 1300.00 | +--------+---------+ 12 rows in set (0.00 sec) | ename | sal | +--------+---------+ | ALLEN | 1600.00 | | WARD | 1250.00 | | JONES | 2975.00 | | MARTIN | 1250.00 | | BLAKE | 2850.00 | | CLARK | 2450.00 | | SCOTT | 3000.00 | | KING | 5000.00 | | TURNER | 1500.00 | | ADAMS | 1100.00 | | FORD | 3000.00 | | MILLER | 1300.00 | +--------+---------+ 12 rows in set (0.00 sec) mysql> select empno,ename,job,comm,sal from emp where sal>=1000 and sal<=3000; +-------+--------+----------+---------+---------+ | empno | ename | job | comm | sal | +-------+--------+----------+---------+---------+ | 7499 | ALLEN | SALESMAN | 300.00 | 1600.00 | | 7521 | WARD | SALESMAN | 500.00 | 1250.00 | | 7566 | JONES | MANAGER | NULL | 2975.00 | | 7654 | MARTIN | SALESMAN | 1400.00 | 1250.00 | | 7698 | BLAKE | MANAGER | NULL | 2850.00 | | 7782 | CLARK | MANAGER | NULL | 2450.00 | | 7788 | SCOTT | ANALYST | NULL | 3000.00 | | 7844 | TURNER | SALESMAN | 0.00 | 1500.00 | | 7876 | ADAMS | CLERK | NULL | 1100.00 | | 7902 | FORD | ANALYST | NULL | 3000.00 | | 7934 | MILLER | CLERK | NULL | 1300.00 | +-------+--------+----------+---------+---------+ 11 rows in set (0.00 sec) mysql> select empno,ename,job,comm,sal from emp where sal>=1000 or sal<=3000; +-------+--------+-----------+---------+---------+ | empno | ename | job | comm | sal | +-------+--------+-----------+---------+---------+ | 7369 | SMITH | CLERK | NULL | 800.00 | | 7499 | ALLEN | SALESMAN | 300.00 | 1600.00 | | 7521 | WARD | SALESMAN | 500.00 | 1250.00 | | 7566 | JONES | MANAGER | NULL | 2975.00 | | 7654 | MARTIN | SALESMAN | 1400.00 | 1250.00 | | 7698 | BLAKE | MANAGER | NULL | 2850.00 | | 7782 | CLARK | MANAGER | NULL | 2450.00 | | 7788 | SCOTT | ANALYST | NULL | 3000.00 | | 7839 | KING | PRESIDENT | NULL | 5000.00 | | 7844 | TURNER | SALESMAN | 0.00 | 1500.00 | | 7876 | ADAMS | CLERK | NULL | 1100.00 | | 7900 | JAMES | CLERK | NULL | 950.00 | | 7902 | FORD | ANALYST | NULL | 3000.00 |
  • 13. | 7934 | MILLER | CLERK | NULL | 1300.00 | +-------+--------+-----------+---------+---------+ 14 rows in set (0.00 sec) mysql> select empno,ename,job,comm,sal from emp where not sal=3000; +-------+--------+-----------+---------+---------+ | empno | ename | job | comm | sal | +-------+--------+-----------+---------+---------+ | 7369 | SMITH | CLERK | NULL | 800.00 | | 7499 | ALLEN | SALESMAN | 300.00 | 1600.00 | | 7521 | WARD | SALESMAN | 500.00 | 1250.00 | | 7566 | JONES | MANAGER | NULL | 2975.00 | | 7654 | MARTIN | SALESMAN | 1400.00 | 1250.00 | | 7698 | BLAKE | MANAGER | NULL | 2850.00 | | 7782 | CLARK | MANAGER | NULL | 2450.00 | | 7839 | KING | PRESIDENT | NULL | 5000.00 | | 7844 | TURNER | SALESMAN | 0.00 | 1500.00 | | 7876 | ADAMS | CLERK | NULL | 1100.00 | | 7900 | JAMES | CLERK | NULL | 950.00 | | 7934 | MILLER | CLERK | NULL | 1300.00 | +-------+--------+-----------+---------+---------+ 12 rows in set (0.00 sec) mysql> update emp set comm=520 where empno=7369; Query OK, 1 row affected (0.37 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from emp; +-------+--------+-----------+------+------------+---------+---------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+-----------+------+------------+---------+---------+--------+ | 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | 520.00 | 20 | | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | | 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 | | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 | | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 | | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 | | 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 | | 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 | | 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 | | 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 | +-------+--------+-----------+------+------------+---------+---------+--------+ 14 rows in set (0.00 sec) mysql> delete from emp where empno=7369; Query OK, 1 row affected (0.01 sec) mysql> select * from emp; +-------+--------+-----------+------+------------+---------+---------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+-----------+------+------------+---------+---------+--------+ | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | | 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 | | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 | | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 | | 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
  • 14. | 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | | 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 | | 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 | | 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 | | 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 | +-------+--------+-----------+------+------------+---------+---------+--------+ 13 rows in set (0.00 sec) ________________________________________________________________________________ _______ mysql> select * from t1; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 5 rows in set (0.00 sec) mysql> select * from t1 union select * from t2; +-----+-------+ | Rno | Name | +-----+-------+ | 1 | amit | | 2 | rohan | | 3 | rahul | | 4 | Nayan | | 5 | pati | | 6 | xyz | | 7 | pqr | +-----+-------+ 7 rows in set (0.00 sec) mysql> select distinct(Rno) as "Common RollNo" from t1 inner join t2 using(Rno); +---------------+ | Common RollNo | +---------------+ | 3 | | 4 | | 5 | +---------------+ 3 rows in set (0.00 sec)