Write Your First SQL Query
This tutorial teaches you SQL basics using SQL Developer. You'll learn SELECT, WHERE, ORDER BY, and JOIN — the building blocks of every database query.
Prerequisites: Download SQL Developer and connect to a database.
Opening the Query Editor
After you download SQL Developer and connect to your database, you're ready to write queries.
- In the Connections panel, right-click your connection
- Select Open SQL Worksheet
- A new query tab opens with a blank editor
Keyboard shortcut: Press Ctrl + N to open a new query window.
The SELECT Statement
SELECT retrieves data from your database. It's the most common SQL command you'll use.
Select All Columns
Use * to select every column from a table:
SELECT * FROM customers;
This returns all rows and all columns from the customers table.
Select Specific Columns
List the column names you want to retrieve:
SELECT first_name, last_name, email
FROM customers;
This returns only the three specified columns, which is more efficient for large tables.
Running Your Query
In SQL Developer, execute your query using:
- Run Statement: Press Ctrl + Enter — runs the current statement
- Run Script: Press F5 — runs all statements in the editor
Results appear in the panel below the editor.
Filtering with WHERE
The WHERE clause filters results to show only rows that match your conditions.
Basic Comparison
SELECT * FROM orders
WHERE total_amount > 100;
Text Matching
SELECT * FROM customers
WHERE country = 'USA';
Multiple Conditions (AND / OR)
-- Both conditions must be true
SELECT * FROM products
WHERE category = 'Electronics' AND price < 500;
-- Either condition can be true
SELECT * FROM customers
WHERE country = 'USA' OR country = 'Canada';
Pattern Matching with LIKE
-- Names starting with 'J'
SELECT * FROM customers
WHERE first_name LIKE 'J%';
-- Email addresses from gmail
SELECT * FROM customers
WHERE email LIKE '%@gmail.com';
% matches any number of characters. _ matches exactly one character.
Sorting with ORDER BY
ORDER BY sorts your results in ascending (ASC) or descending (DESC) order.
Sort Ascending (Default)
SELECT * FROM products
ORDER BY price;
Sort Descending
SELECT * FROM products
ORDER BY price DESC;
Sort by Multiple Columns
SELECT * FROM customers
ORDER BY country ASC, last_name ASC;
This sorts first by country, then by last name within each country.
Limiting Results
When working with large tables, limit the number of rows returned.
MySQL / PostgreSQL / SQLite
SELECT * FROM orders
ORDER BY order_date DESC
LIMIT 10;
Oracle
SELECT * FROM orders
WHERE ROWNUM <= 10
ORDER BY order_date DESC;
-- Oracle 12c and later
SELECT * FROM orders
ORDER BY order_date DESC
FETCH FIRST 10 ROWS ONLY;
SQL Server
SELECT TOP 10 * FROM orders
ORDER BY order_date DESC;
Combining Tables with JOIN
JOIN combines rows from two or more tables based on a related column.
INNER JOIN
Returns only rows that have matching values in both tables:
SELECT orders.order_id, customers.first_name, orders.total_amount
FROM orders
INNER JOIN customers ON orders.customer_id = customers.customer_id;
Using Table Aliases
Make your queries shorter and more readable:
SELECT o.order_id, c.first_name, c.last_name, o.total_amount
FROM orders o
INNER JOIN customers c ON o.customer_id = c.customer_id
WHERE o.total_amount > 100
ORDER BY o.order_date DESC;
LEFT JOIN
Returns all rows from the left table, even if there's no match in the right table:
SELECT c.first_name, c.last_name, o.order_id
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id;
Customers without orders will show NULL for order columns.
Practice Exercise
Try writing these queries in SQL Developer:
- Select all customers from your database
- Find customers whose email contains "gmail"
- List the 5 most recent orders
- Show all orders with customer names (using JOIN)
- Find orders over $100 from customers in the USA
Tip: Use Ctrl + Space in SQL Developer for auto-complete suggestions as you type table and column names.
Next Steps
Continue learning SQL with these guides:
Download SQL Developer Free
The best free SQL client for Windows 10/11. No account required.