Skip to main content
Back to Library
Prompt Engineering Guide

Mastering Write SQL query
on DeepSeek V3

Stop guessing. See how professional prompt engineering transforms DeepSeek V3's output for specific technical tasks.

The "Vibe" Prompt

"Write a SQL query for me. Make sure it's correct. I need to get user data."
Low specificity, inconsistent output

Optimized Version

STABLE
You are an expert SQL query generator. Your task is to write a syntactically correct and optimized SQL query based on the user's request and the provided database schema. **Thought Process:** 1. **Understand Goal:** Identify the core entities and actions requested. 2. **Identify Tables/Columns:** Map entities to tables and required data points to columns. 3. **Determine Joins:** If multiple tables are involved, decide on the appropriate join types and conditions. 4. **Filtering/Ordering:** Apply WHERE, GROUP BY, HAVING, ORDER BY clauses as needed. 5. **Aggregate Functions:** Use COUNT, SUM, AVG, MAX, MIN if aggregations are required. 6. **Optimization Considerations:** Think about indexing, subqueries vs. joins, and efficient clause ordering. 7. **Construct Query:** Assemble the SQL statement. 8. **Review and Refine:** Check for syntax, logic, and potential performance issues. **User Request:** Retrieve all user data including their name, email, and the count of orders they have placed. **Schema:** ```sql CREATE TABLE Users ( user_id INT PRIMARY KEY, username VARCHAR(50) NOT NULL, email VARCHAR(100) UNIQUE NOT NULL, registration_date DATE ); CREATE TABLE Orders ( order_id INT PRIMARY KEY, user_id INT NOT NULL, order_date DATE, total_amount DECIMAL(10, 2), FOREIGN KEY (user_id) REFERENCES Users(user_id) ); ``` **SQL Query:**
Structured, task-focused, reduced hallucinations

Engineering Rationale

The optimized prompt leverages DeepSeek V3's instruction-following and reasoning capabilities much better. It establishes a clear persona ('expert SQL query generator'), outlines a detailed chain-of-thought process that mimics how a human expert would approach the task, explicitly states the user's request, and provides the necessary database schema. This structure guides the model through the steps required to generate an accurate and optimized SQL query, reducing ambiguity and the likelihood of errors. The naive prompt is too vague and lacks context, forcing the model to guess at requirements and schema, often leading to generic or incorrect outputs.

0%
Token Efficiency Gain
The output SQL query must be syntactically correct.
The output SQL query must include user's name, email, and order count.
The output SQL query must correctly join the Users and Orders tables.

Ready to stop burning tokens?

Join 5,000+ developers using Prompt Optimizer to slash costs and boost LLM reliability.

Optimize My Prompts