beginner6 min read

Your First Query

Writing Effective Questions

AI for Database uses large language models to translate your natural-language questions into SQL. The better your question, the better the result. This guide teaches you how to get the most out of every query.

How It Works

When you type a question, AI for Database:

  1. 1Reads your database schema -- table names, column names, relationships, and sample data types.
  2. 2Translates your question into a SQL query using an LLM (GPT-4 or Claude, depending on your configuration).
  3. 3Executes the query against your live database using a read-only connection.
  4. 4Returns results as a table, chart, or single value depending on the shape of the data.

You can always click View SQL to see the generated query and edit it if needed.

Tips for Better Questions

Be specific with time ranges. Instead of "Show me sales", try "Show me total sales for each month in 2024." Time ranges help the AI pick the right date columns and aggregations.

Name your tables or entities. If your database has both a users and customers table, specify which one you mean: "How many customers signed up this quarter?" is clearer than "How many people signed up?"

Ask for comparisons. AI for Database handles comparisons well: "Compare revenue this month vs. last month by product category."

Use follow-up questions. After an initial result, you can refine: "Now break that down by region" or "Only show rows where the amount is above $1,000."

Understanding Results

Results are displayed in the format that best fits the data:

  • Single values (e.g., "What is the total revenue?") appear as a large number card.
  • Tables appear when you ask for lists or detailed records.
  • Charts are generated automatically when the data has a natural x-axis (dates, categories). You can switch between bar, line, and pie charts.

Handling Errors

If the AI generates a query that fails, you will see the error message along with the generated SQL. Common fixes:

  • Check that you are referencing the correct table or column name.
  • Add more context to your question.
  • Try rephrasing: "What is the count of orders grouped by status?" is more explicit than "Show me order statuses."

Saving Queries

Click Save to store the query in your history. You can re-run saved queries at any time, and they will always use live data. Saved queries can also be added to dashboards or used as the basis for alerts.