0% found this document useful (0 votes)
17 views5 pages

Intro To DB - 2 LAB 2 UMER

Uploaded by

Ibad Hussain
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)
17 views5 pages

Intro To DB - 2 LAB 2 UMER

Uploaded by

Ibad Hussain
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/ 5

Lab No 2

CS311 Introduction to Database Systems

Lab#2

Objective:

Basic data retrieval operations in SQL*Plus.

Name of Student: _____________________________________________

Roll No: ______________________________Sec. ___________

Date of Experiment: ___________________________________________

Marks Obtained/Remarks: _____________________________

Signature: _____________________________

1
Lab No 2

EXERCISES

1. Define the different capabilities of SELECT statement? Give an example of


each.

The SELECT statement in SQL is a powerful tool used for querying databases. It has several
capabilities that allow users to retrieve, filter, and manipulate data. Below are the key
capabilities of the SELECT statement, along with examples for each:

● Selecting All Columns:

This is the most basic form of a SELECT statement, where all columns of a table are retrieved.

SELECT * FROM employees;

This will retrieve all columns from the employees table.

● Selecting Specific Columns:

Instead of selecting all columns, you can specify which columns to retrieve.

SELECT first_name, last_name, department FROM employees;

This will retrieve only the first_name, last_name, and department columns from
the employees table.

● Sorting Data with ORDER BY:

You can sort the result set in ascending (ASC) or descending (DESC) order based on one or
more columns.

SELECT first_name, last_name FROM employees ORDER BY last_name ASC;

This will retrieve the first_name and last_name of employees, sorted by last_name
in ascending order.

● Filtering Data with WHERE:

You can filter the rows based on specific conditions using the WHERE clause.

SELECT * FROM employees WHERE department = 'Sales';

This will retrieve all columns for employees who work in the 'Sales' department.

2
Lab No 2
● Grouping Data with GROUP BY:

The GROUP BY clause is used to group rows that have the same values in specified columns.
Often used with aggregate functions (like COUNT, SUM, AVG).

SELECT department, COUNT(*) FROM employees GROUP BY department;

This will return the number of employees in each department.

______

2. Write down SQL queries to perform following functions:-


i. To display the name and department number of employee with number 4.

ii. To display the name and department number of all employees in departments 2 and
4 in alphabetical order by name.

3
Lab No 2

iii. To display the name, department number and hire date of all employees who were
hired in 2021.

iv. To display the name of all employees who have two consecutive Ss in their name
and are in department 104 or their manager is 1.

v. To display the name of all employees of department 2 hired before 2024.

4
Lab No 2

vi. Display the name and salary for all employees whose salary is not in range of
$50000 and $60000.

vii. Display the name, salary and commission for all employees whose commission
amount in greater than their salary increased by 10%.

*****

You might also like