Getting Started with PromptQuery: Your First SQL Query
Welcome to PromptQuery! If you're new to AI-powered SQL generation, this guide will walk you through creating your first query using natural language. By the end of this tutorial, you'll understand how to leverage PromptQuery's context-aware AI to generate accurate SQL queries for your database.
What Makes PromptQuery Different?
Before we dive in, it's important to understand why PromptQuery works differently from other AI SQL tools. Unlike generic AI assistants that guess your database structure, PromptQuery connects directly to your database and uses your actual schema, tables, columns, and relationships to generate queries that work with your real data.
This means:
- ✅ Queries reference your actual table and column names
- ✅ JOINs use your real foreign key relationships
- ✅ Generated SQL respects your database constraints
- ✅ Queries leverage your indexes for better performance
Prerequisites
To follow along with this tutorial, you'll need:
- A PromptQuery account (sign up free)
- Access to a database (PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, or Oracle)
- Basic understanding of SQL concepts (helpful but not required)
Step 1: Connect Your Database
The first step is connecting PromptQuery to your database. This allows the AI to understand your schema and generate accurate queries.
How to Connect
-
Log in to PromptQuery and navigate to the Connections page
-
Click "New Connection" and select your database type
-
Enter your connection details:
- Host/Server address
- Port number
- Database name
- Username and password
- (Optional) SSL settings for secure connections
-
Test the connection to ensure PromptQuery can access your database
-
Save the connection - it will be available for future queries
What Happens During Connection?
When you connect a database, PromptQuery:
- Analyzes your database schema
- Identifies tables, columns, and data types
- Maps foreign key relationships
- Discovers indexes and constraints
- Builds a context map for AI query generation
This process happens automatically and typically takes just a few seconds.
Step 2: Open the SQL Editor
Once your database is connected, you're ready to start writing queries. Navigate to the SQL Editor in PromptQuery, where you'll see:
- Connection selector - Choose which database to query
- Query input area - Where you'll write natural language prompts or SQL
- AI assistant panel - For generating and optimizing queries
- Results area - Where query results will appear
Step 3: Write Your First Natural Language Query
Now for the fun part! Let's generate your first SQL query using natural language.
Example 1: Simple Data Retrieval
Start with something simple. In the query input area, type:
Show me all customers from the customers table
PromptQuery will:
- Recognize you want to query the
customerstable - Generate the appropriate SELECT statement
- Display the SQL it created
- Execute the query and show results
Generated SQL:
SELECT * FROM customers;
Example 2: Filtered Query
Try a more specific request:
Find all orders placed in the last 30 days with a total amount greater than $100
PromptQuery understands:
- You want to filter by date (last 30 days)
- You want to filter by amount (> $100)
- It uses your actual column names (
order_date,total_amount, etc.)
Generated SQL (example):
SELECT *
FROM orders
WHERE order_date >= CURRENT_DATE - INTERVAL '30 days'
AND total_amount > 100;
Example 3: Query with JOINs
Ask for data across multiple tables:
Show me customer names and their order totals from the last month
PromptQuery automatically:
- Identifies the relationship between
customersandorderstables - Creates the appropriate JOIN
- Groups and aggregates data correctly
Generated SQL (example):
SELECT
c.customer_name,
SUM(o.total_amount) AS total_orders
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_date >= CURRENT_DATE - INTERVAL '1 month'
GROUP BY c.customer_name;
Step 4: Review and Refine Generated SQL
After PromptQuery generates SQL, you'll see:
- The generated query - Review it to ensure it matches your intent
- Query explanation - Understand what the query does
- Execution results - See the data returned
- Optimization suggestions - Get tips for better performance
Reviewing Generated Queries
Always review the generated SQL before running it on production data. Check:
- ✅ Does it reference the correct tables?
- ✅ Are the column names accurate?
- ✅ Do the filters match your requirements?
- ✅ Are JOINs using the right relationships?
Making Adjustments
You can:
- Edit the SQL directly if you need to make changes
- Regenerate with a more specific prompt
- Ask for optimization if the query seems slow
- Request an explanation if something is unclear
Step 5: Execute and View Results
Once you're satisfied with the generated SQL:
- Click "Run Query" or press
Ctrl+Enter(Windows/Linux) orCmd+Enter(Mac) - View results in the results panel
- Export data if needed (CSV, JSON, Excel formats available)
- Save the query to your query history for future reference
Tips and Tricks for Better Results
Now that you've written your first query, here are some strategies to get the most accurate results from PromptQuery:
1. Be Specific About Your Intent
Less effective:
Get customer data
More effective:
Show me customer names, emails, and registration dates for customers who signed up in 2024, ordered by registration date
Being specific helps the AI understand:
- Which columns you need
- What filters to apply
- How to sort the results
2. Reference Your Actual Schema
When possible, mention your actual table and column names:
Good:
Find all users in the users table where status equals 'active' and created_at is after January 1st, 2024
This helps PromptQuery match your exact schema structure.
3. Specify Aggregations Clearly
For aggregate queries, be explicit about what you want:
Good:
Calculate the total revenue, average order value, and number of orders per month for the last 6 months
Less clear:
Show me sales stats
4. Use Business Language
You don't need to know SQL syntax. Use natural business language:
- "Show me..." → SELECT
- "Find all..." → SELECT with WHERE
- "Calculate the total..." → SELECT with SUM()
- "Group by..." → GROUP BY
- "Only show..." → WHERE filter
5. Combine Multiple Requirements
You can ask for complex queries in a single prompt:
Show me the top 10 customers by total order value, including their names, email addresses, and the number of orders they've placed, but only include customers who have placed at least 5 orders
PromptQuery will generate the appropriate SQL with:
- JOINs to combine customer and order data
- Aggregations (SUM, COUNT)
- Filtering (HAVING clause for the minimum order count)
- Sorting (ORDER BY with LIMIT)
6. Ask for Explanations
If you're learning SQL, ask PromptQuery to explain queries:
Explain what this query does: [paste SQL]
You'll get a plain English explanation of:
- What tables are involved
- How data is filtered
- What aggregations are performed
- How results are sorted
7. Optimize Existing Queries
Have a slow query? Paste it and ask:
Optimize this query for better performance
PromptQuery will:
- Suggest index usage
- Recommend JOIN optimizations
- Identify potential bottlenecks
- Provide an improved version
8. Handle Edge Cases
Mention edge cases in your prompt:
Find all orders from last month, but exclude cancelled orders and handle NULL values in the shipping_date column
Common Patterns and Examples
Here are some common query patterns you can use:
Finding Recent Records
Show me the 20 most recent orders
Filtering by Date Range
Find all customers who registered between January 1st and March 31st, 2024
Aggregating Data
Calculate total sales, average order value, and number of orders for each product category
Finding Relationships
Show me all products that have never been ordered
Complex Filtering
Find customers who have placed more than 10 orders and spent over $1000, but haven't ordered in the last 30 days
Sorting and Limiting
Show me the top 5 best-selling products by quantity sold this year
Troubleshooting Common Issues
Issue: Generated query references wrong table names
Solution: Be more specific in your prompt. Mention the exact table name, or check that PromptQuery has access to your schema metadata.
Issue: Query returns unexpected results
Solution: Review the generated SQL and check:
- Are filters applied correctly?
- Are JOINs using the right relationships?
- Are data types matching (dates, numbers, strings)?
Issue: Query is slow
Solution: Ask PromptQuery to optimize the query. It will suggest index usage and query improvements based on your database structure.
Issue: Missing columns in results
Solution: Explicitly mention which columns you need in your prompt:
Show me customer_id, name, email, and phone_number from the customers table
Next Steps
Congratulations! You've written your first SQL query with PromptQuery. Here's what to explore next:
- Try more complex queries - Experiment with JOINs, aggregations, and subqueries
- Explore query optimization - Learn how to improve query performance
- Use query history - Save and reuse your favorite queries
- Connect multiple databases - Work with different database types
- Customize metadata access - Configure what schema information PromptQuery uses
Best Practices
As you continue using PromptQuery, keep these best practices in mind:
- ✅ Review generated SQL before executing on production data
- ✅ Start simple and add complexity gradually
- ✅ Use specific prompts for better accuracy
- ✅ Save useful queries to your query history
- ✅ Test queries on development/staging databases first
- ✅ Understand the generated SQL - use explanations to learn
Conclusion
You've learned the basics of using PromptQuery to generate SQL queries from natural language. The key is being specific about what you want and leveraging PromptQuery's understanding of your actual database structure.
Remember: PromptQuery works best when it knows your schema. Keep your database connections active, and the AI will generate increasingly accurate queries as it learns your database structure.
Ready to write more queries? Start using PromptQuery now and experience the power of context-aware SQL generation!
Need Help?

