Intro To DB - 2 LAB 2 UMER
Intro To DB - 2 LAB 2 UMER
Lab#2
Objective:
Signature: _____________________________
1
Lab No 2
EXERCISES
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:
This is the most basic form of a SELECT statement, where all columns of a table are retrieved.
Instead of selecting all columns, you can specify which columns to retrieve.
This will retrieve only the first_name, last_name, and department columns from
the employees table.
You can sort the result set in ascending (ASC) or descending (DESC) order based on one or
more columns.
This will retrieve the first_name and last_name of employees, sorted by last_name
in ascending order.
You can filter the rows based on specific conditions using the WHERE clause.
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).
______
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.
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%.
*****