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

DBM Lab 1 20092023 024213pm

Uploaded by

Sharjeel Sidd
Copyright
© © All Rights Reserved
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)
15 views4 pages

DBM Lab 1 20092023 024213pm

Uploaded by

Sharjeel Sidd
Copyright
© © All Rights Reserved
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

CSL – 220: Database

Management System
SEMESTER BSIT 04

Lab 01: Basic SELECT Statement of SQL


Objective(s):
To learn the basics of SELECT statement.
1. SELECT Statement
A SELECT indicates that we are merely reading information, as opposed to modifying it.
What we are selecting is identified by an expression or column list immediately following the
SELECT. The FROM statement specifies the name of the table or tables from which we are
getting our data.

Syntax:

SELECT <column list>

[FROM <source table(s)>]

Example 1
Select * from Emp;

Selects all the employees records from the database and displays its columns.

Example 2
Select FirstName, LastName from Emp;

Selects data of these two columns from the Employees table

Then there are some functions that can be used in select statement syntax is

Syntax:
SELECT function(<column list>)

[FROM <source table(s)>]

Function are SUM, COUNT, DISTINCT, AVG, MIN and MAX there are many other
function that are also available.

Example 3
SELECT COUNT(*)
Department of Computer Sciences
CSL-220: Database Management System Lab 01: Basic SELECT statement of SQL
FROM emp;

Example 4
SELECT COUNT(DISTINCT sal)

FROM emp;

The WHERE clause immediately follows the

FROM clause and defines what conditions a record has to meet before it will be shown.

Syntax:
SELECT function(<column list>)

[FROM <source table(s)>]

[WHERE]<condition>]

Example 5
SELECT ename,deptno,sal

FROM emp

WHERE empno = 7369;

Department of Computer Sciences


CSL-220: Database Management System Lab 01: Basic SELECT statement of SQL
Exercise

1. Get empno,ename,sal,deptno from emp table.

2. Count total number of employees.

3. Get the highest and the lowest salary from emp table.

4. Calculate net salaries of employee (by adding salary and comm).

5. Display all the deptno that employees belong to, but don’t allow repetition.

6. Display data of all employees who work as Salesman.

7. Display names of employees who work in deptno 20.

8. Calculate one year salary of every employee from emp table.

9. Display the total count of departments from dept table.

10. Display the employee name whose salary is more than 2000 but less than 3500.

11. Display all employee names and their manager number from emp table.

12. Show the average salary of all employees.

13. Show the total salary of all employees.

Department of Computer Sciences


CSL-220: Database Management System Lab 01: Basic SELECT statement of SQL
Department of Computer Sciences
CSL-220: Database Management System Lab 01: Basic SELECT statement of SQL

You might also like