0% found this document useful (0 votes)
3 views2 pages

Dbmsprac 16

The document contains a series of MySQL commands to create and manipulate two tables: 'emp' and 'dept'. It includes inserting records into these tables, performing various select queries, and demonstrating join operations. The results of the queries show relationships between employees and their respective departments.

Uploaded by

lokareswapnil32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Dbmsprac 16

The document contains a series of MySQL commands to create and manipulate two tables: 'emp' and 'dept'. It includes inserting records into these tables, performing various select queries, and demonstrating join operations. The results of the queries show relationships between employees and their respective departments.

Uploaded by

lokareswapnil32
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

mysql> create table emp(empname varchar(25),empno int,empid int);

Query OK, 0 rows affected (0.19 sec)

mysql> insert into


emp(empname,empno,empid)values('swapnil',31,2207),('didar',02,2208),('dnyaneshwar',35,220
8);
Query OK, 3 rows affected (0.03 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select*from emp;


+-------------+-------+-------+
| empname | empno | empid |
+-------------+-------+-------+
| swapnil | 31 | 2207 |
| didar | 2 | 2208 |
| dnyaneshwar | 35 | 2208 |
+-------------+-------+-------+
3 rows in set (0.00 sec)

mysql> create table dept(empname varchar(25),deptno int,deptid int);


Query OK, 0 rows affected (0.37 sec)

mysql> insert into


dept(empname,deptno,deptid)values('swapnil',01,2307),('didar',02,2408),('dnyaneshwar',03,22
08);
Query OK, 3 rows affected (3.73 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select*from dept;


+-------------+--------+--------+
| empname | deptno | deptid |
+-------------+--------+--------+
| swapnil | 1 | 2307 |
| didar | 2 | 2408 |
| dnyaneshwar | 3 | 2208 |
+-------------+--------+--------+
3 rows in set (0.00 sec)

mysql> select emp.empname,


-> emp.empno,
-> emp.empid,
-> dept.deptid
-> from emp,dept
-> where
-> emp.empid=dept.deptid;
+-------------+-------+-------+--------+
| empname | empno | empid | deptid |
+-------------+-------+-------+--------+
| dnyaneshwar | 35 | 2208 | 2208 |
| didar | 2 | 2208 | 2208 |
+-------------+-------+-------+--------+
2 rows in set (0.00 sec)

mysql> select e.empname,e.empid from emp e,dept d where e.empid between d.deptid and
d.deptno;
Empty set (0.00 sec)
mysql> select e.empname"employee",d.empname"manager" from emp e,dept d where
e.empno= d.deptno;
+----------+---------+
| employee | manager |
+----------+---------+
| didar | didar |
+----------+---------+
1 row in set (0.00 sec)

mysql> select emp.empid,emp.empname,dept.deptname from emp left outer join dept on


emp.empno=d.deptno;
ERROR 1054 (42S22): Unknown column 'dept.deptname' in 'field list'
mysql> select emp.empid,emp.empname,dept.empname from emp left outer join dept on
emp.empno=d.deptno;
ERROR 1054 (42S22): Unknown column 'd.deptno' in 'on clause'
mysql> select emp.empid,emp.empname,dept.empname from emp left outer join dept on
emp.empno=dept.deptno;
+-------+-------------+---------+
| empid | empname | empname |
+-------+-------------+---------+
| 2207 | swapnil | NULL |
| 2208 | didar | didar |
| 2208 | dnyaneshwar | NULL |
+-------+-------------+---------+
3 rows in set (0.00 sec)

mysql> select emp.empid,emp.empname,dept.empname from emp right outer join dept on


emp.empno=dept.deptno;
+-------+---------+-------------+
| empid | empname | empname |
+-------+---------+-------------+
| NULL | NULL | swapnil |
| 2208 | didar | didar |
| NULL | NULL | dnyaneshwar |
+-------+---------+-------------+
3 rows in set (0.00 sec)

mysql>

You might also like