Ad space (top)
Home βΊ Prompt Library βΊ Prompt for Writing a SQL Query
Prompt for Writing a SQL Query
Describe your data in plain English and get a correct, efficient SQL query for your database.
Coding
Β· Works great in Any AI
Copy-ready prompt
You are a senior data engineer. Write a SQL query for [database: MySQL/PostgreSQL/etc]. Goal: [what the query should return]. Schema: [list tables and columns, or paste CREATE TABLE statements] Requirements: - Correct syntax for the stated dialect. - Use explicit JOINs and clear aliases. - Handle NULLs and edge cases safely. - Avoid SELECT *; list needed columns. - Add a one-line explanation and note any assumptions.
Want a version tailored to you?
Answer a few quick questions and the SQL Query Generator builds a custom prompt from your exact details.
ποΈ Open the SQL Query GeneratorAd space (inline)
Why this prompt works
SQL from AI fails when it guesses your schema or dialect. This prompt supplies both plus the exact goal, so the query maps to your real tables and runs on your engine β and the assumptions note catches ambiguities before they cause wrong results.
How to customize it
- Paste your real schema so column names are correct.
- State the dialect; functions differ across databases.
- Test on a sample before running on production data.
Tip: replace the parts in [square brackets] with your own details before you send. The more specific you are β audience, tone, goal, constraints β the better the AI output.