Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views4 pages

DBPR 3

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

DBPR 3

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

Vivek Bhosale Practical no :3 roll no.

67 Div C

Aim : Write at least10 SQL queries for suitable database application using SQL DML
statements , Join , Sub-Query and View.

mysql> use vb
Database changed
mysql> create table employee(empid int primary key,empname varchar(20),dept
varchar(10));
Query OK, 0 rows affected (0.05 sec)

mysql> desc employee;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| empid | int | NO | PRI | NULL | |
| empname | varchar(20) | YES | | NULL | |
| dept | varchar(10) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.02 sec)

mysql> create table empdetails(empid int primary key,address varchar(20),pno int);


Query OK, 0 rows affected (0.03 sec)

mysql> desc empdetails;


+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| regid | int | NO | PRI | NULL | |
| address | varchar(20) | YES | | NULL | |
| pno | int | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
insert into employee values(101,'vivek','comp'),(102,'alok','entc'),(103,'aryan','mech');
Query OK, 3 rows affected (0.02 sec)

mysql> select * from employee;


+-------+---------+------+
| empid | empname | dept |
+-------+---------+------+
| 101 | vivek | comp |
| 102 | alok | entc |
| 103 | aryan | mech |
+-------+---------+------+
3 rows in set (0.00 sec)

mysql> insert into empdetails values(101,'pune',9876),(12,'mumbai',8765),


(103,'delhi',7654);
Query OK, 3 rows affected (0.01 sec)

mysql> select * from empdetails;


+-------+---------+------+
| regid | address | pno |
+-------+---------+------+
| 101 | pune | 9876 |
| 12 | mumbai | 8765 |
| 103 | delhi | 7654 |
+-------+---------+------+
3 rows in set (0.00 sec)

Inner Join:
select * from employee inner join empdetails on employee.empid =
empdetails.empid;
+-------+---------+------+-------+---------+------+
| empid | empname | dept | empid | address | pno |
+-------+---------+------+-------+---------+------+
| 101 | vivek | comp | 101 | pune | 9876 |
| 103 | aryan | mech | 103 | delhi | 7654 |
+-------+---------+------+-------+---------+------+
2 rows in set (0.00 sec)

Left Join(outer join):


select * from employee left join empdetails on employee.empname=e
mpdetails.address;
+-------+---------+------+-------+---------+------+
| empid | empname | dept | empid | address | pno |
+-------+---------+------+-------+---------+------+
| 101 | vivek | comp | NULL | NULL | NULL |
| 102 | alok | entc | NULL | NULL | NULL |
| 103 | aryan | mech | NULL | NULL | NULL |
+-------+---------+------+-------+---------+------+
3 rows in set (0.01 sec)

Right Join:
select * from employee right join empdetails on employee.empname=
empdetails.address;
+-------+---------+------+-------+---------+------+
| empid | empname | dept | empid | address | pno |
+-------+---------+------+-------+---------+------+
| NULL | NULL | NULL | 12 | mumbai | 8765 |
| NULL | NULL | NULL | 101 | pune | 9876 |
| NULL | NULL | NULL | 103 | delhi | 7654 |
+-------+---------+------+-------+---------+------+
3 rows in set (0.00 sec)
View:
create view emp(empid,empname) as select e.empid,e.empname from e
mployee e;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from emp;


+-------+---------+
| empid | empname |
+-------+---------+
| 101 | vivek |
| 102 | alok |
| 103 | aryan |
+-------+---------+
3 rows in set (0.00 sec)

Drop View:
drop view emp;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from emp;


ERROR 1146 (42S02): Table 'pr.emp' doesn't exist

You might also like