DS Lab # 04 1
DS Lab # 04 1
DS Lab # 04 1
Date of Conduct: ___________ Submission Date: _________ Signature of the Lab Tutor: ____________
ABILITY TO CONDUCT
LAB PERFORMANCE INDICATOR SUBJECT KNOWLEDGE DATA ANALYSIS AND INTERPRETATION
EXPERIMENT
SCORE
Objective: To retrieve data from tables of a database using SQL SELECT Statement.
Tools: ORACLE/MySQL/Workbench Duration: 3 Hours
The SELECT statement is used to select data from a database. The data returned is stored in a
result table, called the result-set. Some of the Select statements are mentioned below.
Syntax:
SELECT DISTINCT column1, column2, ...
FROM table_name;
2. The SQL ALIAS is used to give a temporary name to a specific column in a table.
Syntax:
SELECT column_name(s)
AS alias_name
FROM table_name;
3. The WHERE clause is used to filter records. It is used to extract only those records that
fulfill a specified condition.
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
1|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
DATABASE SYSTEMS
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 4
4. The ORDER BY keyword is used to sort the result-set in ascending or descending order.
Syntax:
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;
5. The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column. Here are some examples showing different LIKE operators with '%'
Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE columnName LIKE pattern;
Example:
SELECT last_name, job_id, salary
FROM employees
WHERE (job_id = 'SA_REP'
OR job_id = 'AD_PRES')
AND salary > 15000
ORDER BY last_name;
6. The BETWEEN operator selects values within a given range. The values
can be numbers, text, or dates.
2|Page
DEPARTMENT OF TELECOMMUNICATION ENGINEERING
BACHELOR OF SCIENCE IN CYBER SECURITY
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
DATABASE SYSTEMS
(2nd SEMESTER, 1st Year) LAB EXPERIMENT # 4
Syntax:
SELECT Column_Name FROM Table_name
WHERE Column_name BETWEEN value1 AND value2;
Exercise
Consider following tables to write SQL queries.
• EMP (EMPNO, ENAME, DEPARTMENT, HIREDATE, SALARY, CITY )
Set EMPNO as Primary Key.
Note: Read out all the questions before creating the table.
3|Page