query-writing
This tool generates SQL syntax by inspecting database schemas to assist with data extraction, reporting, and troubleshooting.
Install
mkdir -p .claude/skills/query-writing && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1056" && unzip -o skill.zip -d .claude/skills/query-writing && rm skill.zipInstalls to .claude/skills/query-writing
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Writes and executes SQL queries from simple SELECTs to complex multi-table JOINs, aggregations, and subqueries. Use when the user asks to query a database, write SQL, run a SELECT statement, retrieve data, filter records, or generate reports from database tables.Key capabilities
- →Generate SQL queries for single and multi-table operations
- →Inspect database schemas
- →Plan complex JOIN structures
- →Execute queries and format results
- →Troubleshoot SQL syntax errors
How it works
It maps natural language requests to SQL by inspecting table schemas, planning JOINs, and executing queries with safety limits.
Inputs & outputs
When to use query-writing
- →Write complex JOIN queries
- →Retrieve data for reports
- →Troubleshoot SQL syntax errors
- →Filter records across multiple tables
About this skill
Query Writing Skill
Workflow for Simple Queries
For straightforward questions about a single table:
- Identify the table - Which table has the data?
- Get the schema - Use
sql_db_schemato see columns - Write the query - SELECT relevant columns with WHERE/LIMIT/ORDER BY
- Execute - Run with
sql_db_query - Format answer - Present results clearly
Workflow for Complex Queries
For questions requiring multiple tables:
1. Plan Your Approach
Use write_todos to break down the task:
- Identify all tables needed
- Map relationships (foreign keys)
- Plan JOIN structure
- Determine aggregations
2. Examine Schemas
Use sql_db_schema for EACH table to find join columns and needed fields.
3. Construct Query
- SELECT - Columns and aggregates
- FROM/JOIN - Connect tables on FK = PK
- WHERE - Filters before aggregation
- GROUP BY - All non-aggregate columns
- ORDER BY - Sort meaningfully
- LIMIT - Default 5 rows
4. Validate and Execute
Check all JOINs have conditions, GROUP BY is correct, then run query.
Example: Revenue by Country
SELECT
c.Country,
ROUND(SUM(i.Total), 2) as TotalRevenue
FROM Invoice i
INNER JOIN Customer c ON i.CustomerId = c.CustomerId
GROUP BY c.Country
ORDER BY TotalRevenue DESC
LIMIT 5;
Error Recovery
If a query fails or returns unexpected results:
- Empty results — Verify column names and WHERE conditions against the schema; check for case sensitivity or NULL values
- Syntax error — Re-examine JOINs, GROUP BY completeness, and alias references
- Timeout — Add stricter WHERE filters or LIMIT to reduce result set, then refine
Quality Guidelines
- Query only relevant columns (not SELECT *)
- Always apply LIMIT (5 default)
- Use table aliases for clarity
- For complex queries: use write_todos to plan
- Never use DML statements (INSERT, UPDATE, DELETE, DROP)
When not to use it
- →When the user requests DML statements like INSERT, UPDATE, or DELETE
Prerequisites
Limitations
- →Limited to read-only operations
- →Requires schema access to generate accurate queries
How it compares
It automates the entire query lifecycle from schema inspection to result formatting rather than requiring manual SQL writing.
Compared to similar skills
query-writing side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| query-writing (this skill) | 7 | 5mo | No flags | Beginner |
| sql-queries | 18 | 5mo | No flags | Intermediate |
| senior-data-engineer | 21 | 7mo | Review | Advanced |
| powerbi-modeling | 11 | 6mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by langchain-ai
View all by langchain-ai →You might also like
sql-queries
anthropics
Write correct, performant SQL across all major data warehouse dialects (Snowflake, BigQuery, Databricks, PostgreSQL, etc.). Use when writing queries, optimizing slow SQL, translating between dialects, or building complex analytical queries with CTEs, window functions, or aggregations.
senior-data-engineer
davila7
World-class data engineering skill for building scalable data pipelines, ETL/ELT systems, and data infrastructure. Expertise in Python, SQL, Spark, Airflow, dbt, Kafka, and modern data stack. Includes data modeling, pipeline orchestration, data quality, and DataOps. Use when designing data architectures, building data pipelines, optimizing data workflows, or implementing data governance.
powerbi-modeling
github
Power BI semantic modeling assistant for building optimized data models. Use when working with Power BI semantic models, creating measures, designing star schemas, configuring relationships, implementing RLS, or optimizing model performance. Triggers on queries about DAX calculations, table relationships, dimension/fact table design, naming conventions, model documentation, cardinality, cross-filter direction, calculation groups, and data model best practices. Always connects to the active model first using power-bi-modeling MCP tools to understand the data structure before providing guidance.
data-quality-frameworks
wshobson
Implement data quality validation with Great Expectations, dbt tests, and data contracts. Use when building data quality pipelines, implementing validation rules, or establishing data contracts.
fuzzy-matching
dadbodgeoff
Multi-stage fuzzy matching pipeline for entity reconciliation. PostgreSQL trigram pre-filter, salient overlap check, and multi-factor similarity scoring.
data-engineer
sickn33
Build scalable data pipelines, modern data warehouses, and real-time streaming architectures. Implements Apache Spark, dbt, Airflow, and cloud-native data platforms. Use PROACTIVELY for data pipeline design, analytics infrastructure, or modern data stack implementation.