đ§Ē Lab 1.2: Retrieving Data with the SELECT
Statement in Oracle SQL
đ¯ Objective:
This lab introduces the SELECT
statement, the most fundamental and commonly used SQL command. Students will learn how to retrieve data from a table, display specific columns, and apply aliases for better readability.
đ§° Requirements:
- Oracle SQL*Plus or SQL Developer
- Valid Oracle Database connection
- Access to tables like
EMPLOYEES
,DEPARTMENTS
, or similar
đ Understanding the SELECT Statement
The SELECT
statement is used to retrieve data from a database table. You can retrieve all data or just specific columns or rows.
đš Basic Syntax:
SELECT column1, column2, ... FROM table_name;
đ Section A: Retrieve All Columns
✅ Example 1: Display Full Employee Table
SELECT * FROM employees;
This shows every column and row from the employees
table.
đ Section B: Retrieve Specific Columns
✅ Example 2: Select First Name and Salary
SELECT first_name, salary FROM employees;
đ Section C: Using Column Aliases
✅ Example 3: Rename Columns for Readability
SELECT first_name AS "First Name", salary AS "Monthly Salary" FROM employees;
đ Section D: Display Unique Values
✅ Example 4: Get Unique Job IDs
SELECT DISTINCT job_id FROM employees;
đ Section E: Concatenating Columns
✅ Example 5: Combine First and Last Names
SELECT first_name || ' ' || last_name AS "Full Name" FROM employees;
đ Lab Exercise Tasks
- Write a query to show all records from the
departments
table. - Show only
department_name
andmanager_id
columns. - Display a list of distinct job IDs from the
employees
table. - Use aliases to rename
first_name
as “First” andlast_name
as “Last”. - Concatenate
first_name
andlast_name
into a single “Full Name” column. - Try using an incorrect column name (e.g.,
sallary
) and observe the error message.
✅ Learning Outcomes
- Retrieve full or partial records from a table using
SELECT
. - Understand how to use aliases for readability.
- Apply the
DISTINCT
keyword and string concatenation. - Interpret basic SQL error messages and correct mistakes.
đ§ Challenge Activity (Optional)
Write a query that shows the full name and salary of employees who work in department 90:
SELECT first_name || ' ' || last_name AS "Full Name", salary FROM employees WHERE department_id = 90;
āĻোāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāĻ:
āĻāĻāĻি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āĻ āĻāϰুāύ