๐ Using Subqueries in Oracle SQL (Nested Queries Explained)
As part of my ongoing learning with Oracle Autonomous Database, I explored subqueries in SQL. Subqueries allow us to perform more complex queries by using the result of one query inside another.
๐ฏ Objective
The goal of this activity was to:
Understand how subqueries work
Use nested queries to filter data
Perform advanced SQL operations
๐ป Step 1: Creating the Table
CREATE TABLE employees (
emp_id NUMBER,
emp_name VARCHAR2(50),
salary NUMBER
);
๐งช Step 2: Inserting Data
INSERT INTO employees VALUES (1, 'Ali', 50000);
INSERT INTO employees VALUES (2, 'Ahmed', 70000);
INSERT INTO employees VALUES (3, 'Sara', 60000);
INSERT INTO employees VALUES (4, 'Zara', 65000);
๐ Step 3: Viewing Data
SELECT * FROM employees;
๐ Step 4: Using Subquery
SELECT emp_name, salary
FROM employees
WHERE salary > (
SELECT AVG(salary) FROM employees
);
This query returns employees whose salary is greater than the average salary.
๐ก What I Learned
How subqueries work in Oracle SQL
Using nested queries for filtering
Writing more advanced SQL logic
๐ Conclusion
This activity helped me understand how subqueries can be used to perform complex data filtering. It is a powerful concept for real-world database applications.





