query-writing

When to Use This Skill

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "query-writing" with this command: npx skills add langchain-ai/deepagents/langchain-ai-deepagents-query-writing

Query Writing Skill

When to Use This Skill

Use this skill when you need to answer a question by writing and executing a SQL query.

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_schema to 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

  1. Examine Schemas

Use sql_db_schema for EACH table to find join columns and needed fields.

  1. 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

  1. 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;

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)

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Web3

langgraph-docs

No summary provided by upstream source.

Repository SourceNeeds Review
Web3

web-research

No summary provided by upstream source.

Repository SourceNeeds Review
Web3

blog-post

No summary provided by upstream source.

Repository SourceNeeds Review