AI Chat Assistant

Querying Data with AI Chat

Querying Data with AI Chat

WhoDB's AI Chat Assistant transforms database querying from a technical task into a natural conversation. Ask questions in plain English and get instant results with interactive tables, generated SQL, and intelligent error handling.

Getting Started with Simple Queries

Traditional database querying requires knowledge of SQL syntax, table structures, and join relationships. The AI Chat Assistant eliminates these barriers by translating natural language into accurate SQL queries.

Example Prompts

Asking Your First Question

Simple Text Responses

For general questions or informational queries, the assistant provides text responses:

Simple Text Response

Example interactions:

  • "Hello" - Gets a greeting and overview of capabilities
  • "What tables are available?" - Lists your database tables
  • "Explain what the users table contains" - Provides schema information

Retrieving Data with SELECT Queries

The AI assistant excels at generating SELECT queries. Describe what you want — including columns, filters, sorting, and limits — and it produces the SQL:

text

Show me usernames and emails from users created after 2024-01-01, sorted by most recent, limit 10

Generated SQL:

sql

SELECT username, email FROM users
WHERE created_at > '2024-01-01'
ORDER BY created_at DESC
LIMIT 10

You can phrase filtering, sorting, and limiting naturally: "the first 10 users", "products that cost more than $100", "orders with status 'completed'", "sorted by price descending".

Viewing SQL Code

One of the most powerful features is the ability to toggle between table results and the generated SQL code.

SQL Code Toggle

When the assistant returns query results:

Why View SQL Code?

Complex Queries

The AI assistant handles sophisticated queries including aggregations, joins, and multi-step logic.

Aggregation Queries

Count, sum, average, and other statistical operations:

text

Count users by email domain

Generated SQL:

sql

SELECT
  SUBSTRING(email FROM POSITION('@' IN email) + 1) as domain,
  COUNT(*) as user_count
FROM users
GROUP BY domain
ORDER BY user_count DESC

Aggregation Query

All the standard aggregation functions are available through natural phrasing: "How many users do we have?" (COUNT), "What's the total revenue?" (SUM), "Average order value" (AVG), "Highest and lowest prices" (MIN/MAX).

Multi-Table Queries (Joins)

Ask questions that span multiple tables:

text

Show me users and their order counts

Generated SQL:

sql

SELECT
  u.id,
  u.username,
  COUNT(o.id) as order_count,
  SUM(o.total) as total_spent
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
GROUP BY u.id, u.username
ORDER BY total_spent DESC

Dates, Patterns, and Multiple Conditions

The same natural phrasing works for time filters, pattern matching, and combined criteria:

text

Show revenue grouped by month for 2024
Find users with gmail email addresses
Show me active users who joined after 2024-01-01 and have made at least 5 orders

The AI translates these into DATE_TRUNC/date-range filters, LIKE patterns, and combined WHERE conditions or subqueries as appropriate for your database type.

Understanding Query Results

When the AI assistant returns data, you get an interactive table with powerful features.

Interactive Results Table

SQL Query Results

Table Features:

  • Column Headers: Show field names from your query
  • Scrollable: Navigate large result sets
  • Readable Formatting: Data types displayed appropriately

The assistant also provides context about your results, such as the number of rows returned and the columns included. NULL values are clearly distinguishable from empty strings.

Large Result Sets

Chat results are shown in a fixed-height scrollable table containing all returned rows. For queries returning many rows:

  • Scroll within the table to view all data
  • Consider adding LIMIT in your question

Handling Errors

The AI assistant provides clear, helpful error messages when queries fail.

Error Message

Common Error Types

Recovering from Errors

Multi-Turn Conversations

One of the AI assistant's most powerful features is maintaining conversation context for follow-up questions.

Multiple Messages

Building on Previous Queries

The assistant remembers your conversation, so each question can build on the last:

text

You: Show me all users
AI: [Returns 1000 users]

You: Just the first 10, sorted by most recent
AI: [Returns 10 users sorted by created_at DESC]

You: Only active ones
AI: [Adds the status filter, keeping earlier refinements]

Chat History Navigation

Navigate through your previously sent messages using the arrow keys: press Up in the input field to load your previous message, keep pressing to go further back, and press Down to move forward. Edit the loaded message and press Enter to resend.

Example Workflow: Data Exploration

Explore an unfamiliar database systematically:

For a complete walkthrough of this approach, see AI-Powered Data Exploration.

Moving Queries to Scratchpad

When you generate a useful query, save it for future use:

Move to Scratchpad Dialog

For guidance on formulating effective questions, safety, and performance, see AI Chat Assistant Best Practices.

Keyboard Shortcuts

Shortcut
Action
Up Arrow
Previous message in history
Down Arrow
Next message in history
Enter
Send message

Arrow keys navigate through your previously sent messages, letting you quickly reload, edit, and resend earlier questions.

Troubleshooting

Limitations

Understanding limitations helps set appropriate expectations:

Privacy and Security

Sent to AI:

  • Your question text
  • Database schema (table and column names)
  • Database type (PostgreSQL, MySQL, etc.)

Never Sent:

  • Actual data from your tables
  • Query results
  • Connection credentials
  • Passwords or sensitive configuration

For sensitive data: use local models for complete privacy, review your organization's policies on external AI services, avoid sensitive schema names with cloud providers, and use read-only connections for exploratory querying. See AI Chat Assistant Best Practices for full guidance.

Next Steps

Modifying Data

Learn how to safely update, insert, and delete data using the AI assistant

Conversation Features

Master advanced conversation features and context management

Scratchpad Integration

Move generated queries to Scratchpad for refinement and reuse

Best Practices

Discover optimal patterns for AI-assisted database work