0% found this document useful (0 votes)
56 views

Queries of Joins: Presented By: Monika Segal Asst. Professor Dept. CSE

The document discusses various types of joins that can be performed between two database tables in SQL. It demonstrates creating two sample tables called dept_m and emp_m, inserting data into them, and then shows examples of different join queries between the tables including inner joins, outer joins, natural joins, and aggregate functions used with group by. The document is presenting on the topic of queries of joins in SQL.
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)
56 views

Queries of Joins: Presented By: Monika Segal Asst. Professor Dept. CSE

The document discusses various types of joins that can be performed between two database tables in SQL. It demonstrates creating two sample tables called dept_m and emp_m, inserting data into them, and then shows examples of different join queries between the tables including inner joins, outer joins, natural joins, and aggregate functions used with group by. The document is presenting on the topic of queries of joins in SQL.
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/ 7

Queries of Joins

Presented By :
Monika Segal
Asst. Professor
Dept. CSE

create table dept_m


(
id int primary key,
name varchar(20)
);

insert into dept_m values (101,'CSE');

create table emp_m


(
id int primary key,
name varchar(20),
salary number(8),
dept_id int
references dept_m(id)
);
insert into emp_m values (1,'A',36000, 101 );
insert into emp_m (id, name, salary) values (6,'F',54000);

select * from dept_m;


select * from emp_m;
select * from dept_m natural join emp_m;
select * from dept_m inner join emp_m on dept_m.id =
emp_m.dept_id;
select * from dept_m, emp_m where dept_m.id = emp_m.dept_id;
select * from dept_m, emp_m where dept_m.id= emp_m.dept_id
and emp_m.salary >40000;
select * from dept_m, emp_m where emp_m.salary >40000;

select * from dept_m cross join emp_m;

create table emp_m1


(
e_id int primary key,
name varchar(20),
salary number(8),
id int
references dept_m(id)
);
alter table emp_m1 rename column name to e_name;

select * from dept_m natural join emp_m;


select * from dept_m natural join emp_m1;

select * from dept_m full outer join emp_m on dept_m.id =


emp_m.dept_id;
select * from dept_m, emp_m where dept_m.id(+) =
emp_m.dept_id;
select * from dept_m right outer join emp_m on dept_m.id =
emp_m.dept_id;
select * from dept_m, emp_m where dept_m.id =
emp_m.dept_id(+);
select * from dept_m left outer join emp_m on dept_m.id =
emp_m.dept_id;
select * from dept_m inner join emp_m on dept_m.id =
emp_m.dept_id;
select * from dept_m, emp_m where dept_m.id = emp_m.dept_id;

select a.e_id,a.e_name,b.e_id, b.e_name from


emp_m1 a , emp_m1 b where a.mgr_id=b.e_id;
select * from dept_m , emp_m;

select * from dept_m where id in ( select dept_id from


emp_m where salary > 40000);

select * from dept_m where id in( select dept_id from


emp_m group by dept_id having count(id)>1);

select sum(salary), avg(salary), min (salary),


max(salary), count(*), count(dept_id) from
emp_m;

select sum(salary) from emp_m group by


dept_id;
select sum(salary) from emp_m group by
dept_id having sum(salary)> 90000;

You might also like