Skip to main content
SQL Developer — docs/first-query.md
SELECT · 15 min

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.

~/tutorial/first-query.spec tutorial overview

# Tutorial

level = Beginner

time = 15 minutes

topics = SELECT · WHERE · ORDER BY · LIMIT · JOIN

prereq = SQL Developer + a database connection

# Examples

dialects = MySQL · PostgreSQL · Oracle · SQL Server · SQLite

tables_used = customers · orders · products

// includes a practice exercise at the end

Opening the Query Editor

After you download SQL Developer and connect to your database, you're ready to write queries.

  1. In the Connections panel, right-click your connection
  2. Select Open SQL Worksheet
  3. 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:

~/queries/select-all.sqlSELECT *

SELECT * FROM customers;

Select Specific Columns

List the column names you want to retrieve:

~/queries/select-cols.sqlspecific columns

SELECT first_name, last_name, email

FROM customers;

Running Your Query

  • 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.

~/queries/where-basic.sqlcomparison

SELECT * FROM orders

WHERE total_amount > 100;

~/queries/where-text.sqltext matching

SELECT * FROM customers

WHERE country = 'USA';

~/queries/where-and-or.sqlAND / 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';

~/queries/where-like.sqlLIKE pattern

-- 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.

~/queries/order-asc.sqlascending

SELECT * FROM products

ORDER BY price;

~/queries/order-desc.sqldescending

SELECT * FROM products

ORDER BY price DESC;

~/queries/order-multi.sqlmultiple 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. Syntax differs by database.

~/queries/limit-mysql.sqlMySQL / Postgres / SQLite

SELECT * FROM orders

ORDER BY order_date DESC

LIMIT 10;

~/queries/limit-oracle.sqlOracle

-- Oracle 12c and later (preferred)

SELECT * FROM orders

ORDER BY order_date DESC

FETCH FIRST 10 ROWS ONLY;

-- Older Oracle

SELECT * FROM orders

WHERE ROWNUM <= 10

ORDER BY order_date DESC;

~/queries/limit-sqlserver.sqlSQL 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:

~/queries/inner-join.sqlINNER JOIN

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:

~/queries/inner-join-alias.sqlwith aliases

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:

~/queries/left-join.sqlLEFT JOIN

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 to lock in what you learned.

  1. Select all customers from your database
  2. Find customers whose email contains "gmail"
  3. List the 5 most recent orders
  4. Show all orders with customer names (using JOIN)
  5. 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 with these related guides.

NEXT

Schema Explorer

Navigate tables, views, indexes, and stored procedures in the Connections panel.

Read guide →

NEXT

Format SQL

Auto-format messy SQL into clean, readable code with Ctrl+F7.

Learn how →

NEXT

Run SQL Scripts

Execute .sql files and multiple queries with F5.

Learn how →

~/downloads ready.sh

Download SQL Developer Free

The best free SQL client for Windows 10/11. No account required.

// platformWindows 10/11 (64-bit)
// licenseFree · No Oracle account required