Mastering Oracle Live SQL
Learn Oracle Live SQL Fundamentals with Examples, Diagrams, and Queries. Perfect for mastering SQL and JavaScript interview preparation.
🌟 Introduction
In today’s tech-driven world, data is the backbone of every intelligent system. Whether it’s a JavaScript application fetching data from a backend or a business dashboard visualizing insights, SQL (Structured Query Language) plays a pivotal role.
If you’re a JavaScript developer or aspiring full-stack engineer, understanding SQL is not just a “plus” — it’s a must-have skill. And there’s no better platform to learn it interactively than Oracle Live SQL — a free, browser-based playground built by Oracle to let you write, execute, and share SQL queries online.
In this first part of our 4-part series, you’ll learn everything you need to get started with Oracle Live SQL — from setup, schemas, and writing basic queries, to understanding how SQL powers real-world web applications.
🧭 What is Oracle Live SQL?
Oracle Live SQL is an online environment where you can run SQL statements directly in your browser — without installing any database locally. It’s hosted by Oracle and connected to a cloud-based Oracle Database, which includes sample schemas like HR, SH, and OE.
Key Benefits:
1. Practicing SQL queries hands-on.
2. Running PL/SQL blocks.
3. Sharing code with mentors, peers, or interviewers.
4. Testing Oracle-specific SQL syntax without setup headaches.
🧩 Key Features of Oracle Live SQL
Feature | Description |
|---|---|
💻 Browser-Based | No installation — just sign in and start coding. |
🧠 Built-in Schemas | Preloaded databases like HR and SH for realistic practice. |
📚 Tutorial Library | Dozens of guided exercises and learning modules. |
💾 My Scripts | Save, organize, and share your SQL queries easily. |
🔍 Schema Browser | Explore tables, columns, and relationships visually. |
🧾 Execution History | Review and re-run your previous queries instantly. |
⚙ Setting Up Oracle Live SQL
1. Visit 👉 https://livesql.oracle.com
2. Click “Sign In” (create a free Oracle account if you don’t have one).
3. Once inside, click “SQL Worksheet” — this is your coding playground.
4. You’ll see a workspace with three main panels:
Editor → where you write queries
Results → displays query output
Schema Browser → explore available tables
🏗 Understanding the Default HR Schema
Oracle provides a sample HR (Human Resources) schema that’s ideal for beginners. It includes several interconnected tables, such as:
Table | Description |
|---|---|
| EMPLOYEES | Contains employee details like names, salary, job ID, etc. |
| DEPARTMENTS | Lists department names, IDs, and locations. |
| JOBS | Holds job roles and salary ranges. |
| LOCATIONS | Provides address and location data. |
| COUNTRIES | Includes country names and regions. |
🧩 ER Diagram of HR Schema
Here’s a simplified diagram of how these tables connect:
EMPLOYEES ───< DEPARTMENTS ───< LOCATIONS ───< COUNTRIES
│
└── JOBSRelationship Explanation:
Each department can have many employees.
Each location can host many departments.
✍ Writing Your First SQL Queries in Oracle Live SQL
1. Retrieve All Employee Data
SELECT * FROM employees;
Explanation:
* means “all columns.”⚠️ Avoid using
* in production — select only required columns.2. Select Specific Columns
SELECT first_name, last_name, salary
FROM employees;
Tip: Use clear column names to improve readability.
3. Filter Rows Using WHERE
SELECT first_name, last_name, department_id
FROM employees
WHERE department_id = 10;
Explanation:
Filters only employees in department 10.
4. Sort Data with ORDER BY
SELECT first_name, salary
FROM employees
ORDER BY salary DESC;
Explanation:
ORDER BY sorts results — ASC for ascending (default) or DESC for descending.
5. Combine Filters with AND / OR
SELECT first_name, last_name, salary
FROM employees
WHERE department_id = 50 AND salary > 8000;
Logic:
Shows employees in department 50 earning more than 8000.
📊 Aggregate Functions — SUM, COUNT, AVG, MIN, MAX
SQL provides built-in functions to summarize data:
SELECT department_id,
COUNT(*) AS total_employees,
AVG(salary) AS average_salary
FROM employees
GROUP BY department_id;
Explanation:
COUNT(*)→ counts employees in each departmentAVG(salary)→ computes average salaryGROUP BY→ groups rows by department
🔗 Joining Tables in Oracle Live SQL
1. INNER JOIN
SELECT e.first_name, e.last_name, d.department_name
FROM employees e
JOIN departments d
ON e.department_id = d.department_id;
Explanation: Combines employee and department data where IDs match.
2. LEFT JOIN
SELECT e.first_name, d.department_name
FROM employees e
LEFT JOIN departments d
ON e.department_id = d.department_id;
Explanation:
Shows all employees, even those without a department (null department name).
📐 Understanding SQL Clauses Flow
Here’s how a SQL query executes internally:
1️⃣ FROM → Identify tables
2️⃣ WHERE → Filter rows
3️⃣ GROUP BY → Group data
4️⃣ HAVING → Filter groups
5️⃣ SELECT → Pick columns
6️⃣ ORDER BY → Sort results
💡 Real-World Example: Employee Dashboard Query
Imagine building a salary dashboard in JavaScript using this query:
SELECT d.department_name,
COUNT(e.employee_id) AS total_employees,
ROUND(AVG(e.salary), 2) AS avg_salary
FROM employees e
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.department_name
ORDER BY avg_salary DESC;
Use Case:
This SQL output can be fetched via API and visualized in JS charting libraries like Chart.js or D3.js.
🧩 Interactive Tip — Using the Schema Browser
In the Schema Browser:
1. Click EMPLOYEES → view columns and data types
2. Expand Constraints → see foreign keys
3. Use Data Preview → check sample data
This helps visualize table relationships for JOIN queries and ER modeling.
🔎 Query Optimization Tips for Beginners
✅ Use specific column names instead of SELECT *
✅ Create indexes on columns in WHERE or JOIN
✅ Run EXPLAIN PLAN FOR to check performance
✅ Prefer joins over nested subqueries
✅ Use aliases (e, d, etc.) for clarity
Example:
EXPLAIN PLAN FOR
SELECT e.first_name, e.salary, d.department_name
FROM employees e
JOIN departments d
ON e.department_id = d.department_id;
🧰 Debugging in Oracle Live SQL
If you encounter ORA-00904: invalid identifier, verify the column names carefully.
Use Run Script for multiple commands.
Check the Execution Plan for performance insights.
🧑💻 Hands-On Practice Challenge
Try this exercise in Oracle Live SQL:
-- Find the top 5 highest-paid employees
SELECT first_name, last_name, salary
FROM employees
ORDER BY salary DESC
FETCH FIRST 5 ROWS ONLY;
Bonus Challenge:
Modify it to include the department name using a JOIN.
✍️ By Ashish | 2025-10-21T09:01:55.999Z