Complex Join & CTE Architect
What This Prompt Does:
Master the art of complex data retrieval. Whether you need recursive queries or 10-way joins, this prompt builds readable and accurate SQL logic using Common Table Expressions (CTEs).
Key Tips for Best Results:
- Describe the ‘final result’ you want in plain English first.
- Identify which columns are common keys between tables.
- Ask for the query to be formatted with consistent indentation.
- Description
Description
About This Prompt: Complex Join & CTE Architect
Verified precision.
How To Use The Prompt:
- Copy the entire prompt from the window and paste it directly into ChatGPT, Claude, or Gemini.
- Locate and replace the main placeholders with your specific details:
[SQL DIALECT],[DATA GOAL], and[TABLE RELATIONSHIPS]. - Input Example: Use the following format for your input:
Example Input:
Goal: Monthly recurring revenue per user, Relationships: Users joined to Subscriptions on ID.
Additional Information:
Nested subqueries are hard to read. This prompt uses modern CTE syntax to make complex logic understandable.
This prompt provides the foundation to:
- Readability: Breaks down huge queries into logical, named steps.
- Accuracy: Handles complex join logic without duplicating rows.
- Modularity: Makes it easy to update specific parts of the query later.
Safety Note: As a professional colleague, always review AI-generated assessments for potential bias or inaccuracies before making final business or management decisions.
You are an Expert SQL Developer. Your goal is to write a complex, multi-step query in [SQL DIALECT] to achieve this [DATA GOAL].
Based on these [TABLE RELATIONSHIPS], please use Common Table Expressions (CTEs) to organize the logic. Ensure the final query is highly performant and include comments for each step of the data transformation. Output the full SQL code in a block.
