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

Dbms Exp 6

MYSQL join QUERIES

Uploaded by

piyush thakur
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)
15 views4 pages

Dbms Exp 6

MYSQL join QUERIES

Uploaded by

piyush thakur
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/ 4

TABLES DESCRIPTION

mysql> desc emp;

mysql> desc works;

mysql> desc comp;

mysql> desc manages;


TABLES WITH VALUES
mysql> select * from emp;

mysql> select * from works;

mysql> select * from comp;

mysql> select * from manages;


QUERIES
1. Find the names and city of all employees who works for Infoysys and earn
upto 50000
mysql> select emp.ename,city from emp,works where emp.ename=works.ename and
cname='INFOSYS' and salary<=50000;

2. Name all the employees who lives in same city of the company in which they
work
mysql> select emp.ename from emp,works,comp where emp.ename=works.ename and
works.cname=comp.cname and emp.city=comp.city;

3. Name of all employees who lives in same street as there manager


mysql> select e1.ename from emp e1,emp e2,manages m
-> where e1.ename=m.ename and e2.ename=m.mname and e1.street=e2.street;
4. Names of all the employees who do not work for Infosys
mysql> select ename from works where cname!='INFOSYS';

5. Name of all employees who earn more than every employee of Infosys
mysql> select ename from works where salary>
-> (select max(salary) from works where cname='INFOSYS');

6. Name of all the employees who earn more than avg salary of all employees of
their companies
mysql> select w1.ename from works w1 where salary>
-> (select avg(salary) from works w2 where w1.cname=w2.cname);

7. Name and city of the company having smallest payroll


mysql> select comp.cname,city from works,comp where works.cname=comp.cname group by
cname having sum(salary) <= all
-> (select sum(salary) from works group by cname);

You might also like