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

Q: Retrieve DOB, Address From Table Employee Whose Fname Is Karan ?

This document contains sample SQL queries and their outputs. The queries retrieve data from employee and department tables, including details like name, address, department, salary, and more. They also perform operations like filtering, sorting, aggregation, and more. In total, there are 20 SQL queries and their outputs listed.

Uploaded by

Jimmy Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
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)
48 views

Q: Retrieve DOB, Address From Table Employee Whose Fname Is Karan ?

This document contains sample SQL queries and their outputs. The queries retrieve data from employee and department tables, including details like name, address, department, salary, and more. They also perform operations like filtering, sorting, aggregation, and more. In total, there are 20 SQL queries and their outputs listed.

Uploaded by

Jimmy Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
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

Q : Retrieve DOB, Address from table Employee whose Fname is Karan ?

SQL> select dob,address from employee where fname = 'Karan';


DOB

ADDRESS

--------- -----------------------------07-MAR-85 23/2 Pitampura Delhi

Q : Retrieve fname,lname,address of employee who belongs to HR department ?


SQL> select fname, lname,address from employee, department where dname='HR' and dnumber = dno;
FNAME

LNAME

ADDRESS

------------ ------------ -----------------------------Karan

Grover

23/2 Pitampura Delhi

Q : Retrieve fname of employee and his supervisors fname ?


SQL> select e.fname, s.fname as manager
2 from employee e, employee s
3 where e.superssn=s.ssn;
FNAME

MANAGER

------------ -----------Ram

Ram

Jimmy

Jimmy

Prashant

Prashant

Karan

Karan

Raj

Raj

Q: Retrieve all SSN from employee table ?


SQL> select ssn from employee;
SSN
---------1001
1002
1003
1004
1005

Q : Retrieve all ssn,dname using Cartesian product from employee and department table ?
SQL> select ssn,dname from employee,department;
SSN DNAME
---------- -----------1001 Marketing
1002 Marketing
1003 Marketing
1004 Marketing
1005 Marketing
1001 Account
1002 Account
1003 Account
1004 Account
1005 Account
1001 HR
1002 HR
1003 HR
1004 HR
1005 HR
1001 Sales
1002 Sales
1003 Sales
1004 Sales
1005 Sales
1001 Advt
1002 Advt
1003 Advt
1004 Advt
1005 Advt

Q : Retrieve all details of employee whose DNO is 5 ?


SQL> select * from employee where dno=5;
SSN FNAME MINIT LNAME ADDRESS

SALARY SUPERSSN

DOB

AGE

DNO

---------- ---------- --------- ---------- ----------------- ----------- ---------------------------------------- ---------- --------------- ----------1005 Raj

Aggarwal BA-297 Tagore Garden Delhi

15000

Q : Retrieve all salaries from employee ?


SQL> select salary from employee;
SALARY
---------22000
50000
80000
24000
15000

Q : Retrieve distinct salary from employee ?


SQL> select DISTINCT(salary) from employee;
SALARY
---------24000
50000
15000
22000
80000

Q : Retrieve fname from employee table whose address is in Pitampura ?


SQL> select fname from employee where address LIKE '%Pitampura%';
FNAME
-----------Karan

1005

04-APR-89

22

Q : Retrieve all employees in department 5 whose salary is between 10000 and 20000 ?
SQL> select * from employee where dno=5 and salary between 10000 and 20000;
SSN FNAME

MINIT

LNAME

ADDRESS

SALARY SUPERSSN DOB

AGE

DNO

---------- ---------- --------- ---------- ---------------------- ------------- ---------------- ------ -------------- -----------------------------1005 Raj

Aggarwal

BA-297 Tagore Garden Delhi 15000

1005

04-APR-89

22

Q : Retrieve all details of employee whose salary > 20000 according to their department no. ?
SQL> select * from employee where salary>20000 order by dno;
SSN FNAME

MINIT

LNAME

ADDRESS

SALARY SUPERSSN

DOB

AGE

DNO

---------- ---------- --------- ---------- ------------------- ---------------- --------------------------- ---------------------- ---------------1003 Prashant

Arora

Amba Enclave Rohini Delhi

80000

1003

13-NOV-90

22

1002 Jimmy

Gupta

WZ-11 Punjabi Bagh Delhi

50000

1002

11-JAN-92

21

1004 Karan

Grover

23/2 Pitampura Delhi

24000

1004

07-MAR-85

28

Singh

124 Saraswati Vihar Delhi

22000

1001

11-NOV-83

30

1001 Ram

Q : Retrieve no. of rows in employee table ?


SQL> select count(SSN) as NO_OF_ROWS from employee;
NO_OF_ROWS
------------------5
Q : Retrieve sum of salary an average of salary from employee ?
SQL> select SUM(SALARY), AVG(SALARY) from employee;
SUM(SALARY) AVG(SALARY)
----------- -------------------------191000

38200

You might also like