How to write a basic SQL query
You need to retrieve records from a database without changing the data. The method below walks you through the work without assuming you know the software.
Before you start
FILE OPTIONAL: a relevant existing document. If you have it, select + or the paperclip, choose Upload file and wait until its name appears. Otherwise start a new chat and describe what you need. Never upload confidential material to an unapproved tool.
Copy this into your AI tool
Example, follow-up prompt and final checks
Example conversation
AI might ask: What information do you want from your database?
You might reply: A list of customer account openings by month.
Example result
SELECT branch, COUNT(*) AS accounts
FROM example_accounts
GROUP BY branch;
(Read-only example with fictional table name.)
Improve your result
Use a safe test copy before touching live systems, and confirm any change with the authorised owner.
Add grouping and a count by one category if appropriate.
Before you use it
Run only on an authorised database and check sample rows.