How to use AI to create the ideal MySQL SQL queries?
Use AI to write MySQL queries from plain English descriptions. Describe what data you want in natural language, and Indiequery generates the SQL query for you - complete with proper syntax, table joins, and formatting.
How to Access the AI Query Builder
Open any query in the query editor. You'll see two tabs at the top: SQL Mode and AI Builder. Click the AI Builder tab (marked with a sparkles icon) to switch from manual SQL writing to AI-powered query generation.
The AI Builder shows a text area where you describe your query in plain English. Type what data you want to retrieve, and the AI translates it into working SQL.
Generate Queries from Plain English
Describe your query naturally, like you'd explain it to a colleague. The AI understands database terminology and knows your schema.
Examples:
"Get the 10 most recent orders with customer email and total amount"
"Show daily signups for the last 30 days"
"Find all users who haven't logged in during the past week"
"Count active subscriptions by tier"
Click Generate Query after typing your description. The AI analyzes your database schema - tables, columns, data types, primary keys - and writes SQL that matches your request.
What the AI Returns
The AI provides two things:
Explanation - A brief description of what the generated query does and why it's structured that way. This helps you understand the SQL even if you're not familiar with advanced syntax.
SQL Query - Formatted, executable SQL code ready to run. The query uses proper MySQL syntax with correct table names, column references, and JOIN logic based on your actual schema.
The generated SQL appears in a preview window with syntax highlighting. Review both the explanation and the code before using it.
Use the Generated Query
Click Use This Query to insert the AI-generated SQL into your editor. The interface automatically switches back to SQL Mode, where you see the full query ready to run.
You can modify the AI-generated query manually if needed. Treat it as a starting point - adjust WHERE clauses, add columns, change sorting, or combine it with other logic.
Click Run Query to execute the SQL and see results. The AI writes valid queries, but you might want to add a LIMIT clause or adjust filters based on your specific needs.
How the AI Understands Your Database
The AI knows your complete database schema when generating queries. It sees:
- All table names in your database
- Column names and their data types
- Primary key columns
- Which tables likely connect to each other
This context means the AI writes queries using actual table and column names from your schema. It doesn't guess or make up field names - it references real columns that exist in your database.
The AI also considers your current query if you have SQL already written in the editor. When you switch to AI Builder with existing SQL, the AI sees that code and can help you improve, extend, or rewrite it based on your new instructions.
Modify or Extend Existing Queries
Already have a query but need to add filters or change the logic? Switch to AI Builder and describe your changes. The AI sees your current SQL and modifies it based on your instructions.
Example: You have SELECT * FROM orders WHERE status = 'completed' in your editor. Switch to AI Builder and type "add customer email and order date, sort by most recent first". The AI updates your query to include those columns and add proper sorting.
This workflow works better than starting from scratch when you have partial SQL that just needs adjustments.
AI Query Limits
Indiequery includes AI query generation in all paid plans. Free accounts have limited AI queries per month. Check your account settings to see your current usage and limits.
The AI also has a rate limit of 10 queries per minute to prevent abuse and ensure service quality for all users. If you hit this limit, wait a minute before generating more queries.
When AI Works Best
AI query generation excels at:
Standard queries - Filtering, sorting, joining tables, aggregating data with GROUP BY, counting records.
Time-based analysis - "Last 30 days", "this month", "past week" queries with proper date functions.
Multi-table queries - The AI handles JOINs when you describe relationships like "orders with customer details" or "users and their subscription status".
Aggregations - Counting, summing, averaging, and grouping data across different dimensions.
The AI writes read-only SELECT queries. It can't generate INSERT, UPDATE, DELETE, or schema modification statements (Indiequery is a read-only database explorer).
Review Generated Queries
Always review AI-generated SQL before running it on important data. The AI is accurate but can misinterpret ambiguous instructions.
Check that:
- Table and column names match your expectations
- JOIN logic connects the right tables
- WHERE filters apply the constraints you intended
- LIMIT clauses prevent accidentally returning millions of rows
The explanation helps you verify the query logic matches your request. If something looks wrong, go back to AI Builder, refine your description, and generate again.
Tips for Better AI Queries
Be specific about what you want - "Show user email, signup date, and total order count for users who signed up in January" works better than "get some user data".
Mention time ranges explicitly - "Last 7 days", "this month", "between January 1 and March 31" instead of vague "recent" or "old".
Name the columns you need - Listing specific columns gets better results than asking for "everything about orders". The AI can infer some columns but explicit requests are clearer.
Specify sort order - "Sort by newest first", "order by amount descending", "alphabetically by name" tells the AI exactly how to structure ORDER BY clauses.
Describe relationships naturally - "Orders with customer names" or "users and their most recent login" helps the AI understand which tables to join.
Combine AI with Manual Editing
Use AI to generate the query structure, then manually tweak details. The AI handles the tedious parts - remembering exact table names, writing JOIN syntax, setting up date functions. You add the final touches like adjusting LIMIT values or adding specific WHERE conditions.
This hybrid approach is faster than writing SQL from scratch and more precise than relying entirely on AI.