Writing SQL Queries

Introduction

This tutorial teaches you how to write and execute SQL queries in DBWillow's SQL Editor.

Opening the SQL Editor

  1. Connect to a database
  2. Click the "SQL Editor" tab
  3. Editor opens with a new query tab

Your First Query

Simple SELECT

Start with a basic query:

SELECT * FROM users;
  1. Type the query
  2. Press Ctrl+Enter (or Cmd+Enter on macOS)
  3. Results appear below

Selecting Specific Columns

SELECT id, name, email
FROM users;

Adding Conditions

SELECT *
FROM users
WHERE status = 'active';

Query Execution

Execute Button

  • Click the "Execute" button in toolbar
  • Or press Ctrl+Enter / Cmd+Enter

Multiple Queries

Execute multiple queries:

SELECT * FROM users;
SELECT * FROM orders;

Each query runs separately.

Working with Results

Viewing Results

  • Results appear in panel below editor
  • Scroll to see all rows
  • Use pagination for large results

Exporting Results

  1. Execute query
  2. Click "Export" button
  3. Choose format (CSV, JSON, Excel)
  4. Download file

Advanced Queries

JOINs

SELECT 
  u.name,
  o.total,
  o.order_date
FROM users u
JOIN orders o ON u.id = o.user_id;

Aggregations

SELECT 
  category,
  COUNT(*) as count,
  AVG(price) as avg_price
FROM products
GROUP BY category;

Subqueries

SELECT *
FROM users
WHERE id IN (
  SELECT user_id
  FROM orders
  WHERE total > 100
);

Best Practices

Formatting

  • Use consistent indentation
  • Break long queries into multiple lines
  • Add comments for complex logic

Performance

  • Test on small datasets first
  • Use LIMIT for exploration
  • Add indexes for frequently queried columns

Safety

  • Be careful with DELETE/UPDATE
  • Use transactions for modifications
  • Test on development databases first

Using AI Assistant (Premium)

Natural Language Queries

Instead of writing SQL:

  1. Click "AI Assistant"
  2. Describe what you want: "Show me all active users"
  3. AI generates SQL
  4. Review and execute

Refining Queries

  1. AI generates base query
  2. Ask for modifications: "Add a filter for premium users"
  3. AI updates query
  4. Execute refined query

Next Steps