Skip to main content

Command Palette

Search for a command to run...

๐Ÿš€ Using Subqueries in Oracle SQL (Nested Queries Explained)

Updated
โ€ข2 min read

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.

2 views

More from this blog

๏ฟฝ

๐Ÿš€ Getting Started with Oracle Autonomous Database (Free Tier) โ€“ My First Hands-on Experience

15 posts