StackOverflow has a great page in their help section on how to create a minimal, complete, and verifiable, example (MCVE).
I think it would be very helpful if we had a similar document showing how to create a simple MCVE for SQL related questions.
Something like this:
How to create a Minimal, Complete, and Verifiable Example for database-related questions
Database-related questions asking for practical advice will get the most helpful answers if they provide a framework others can use to reproduce that problem.
With that in mind, when asking a question please create a framework that is:
- Minimal – Use as little code as possible that still produces the same problem
- Complete – Provide all parts needed to reproduce the problem
- Verifiable – Test the code you're about to provide to make sure it reproduces the problem
Reducing the code to the bare minimum necessary to convey the problem makes the question easier to ask, and inherently easier to answer. Win-win. If you have a question about a query that has 400 columns, and all 400 columns are not required for the answer, only show the two or three columns that are pertinent to the question.
Include all the tables, queries, indexes, constraints, and other parts as necessary to ensure the person answering your question has all the information at the outset. When including these pieces, provide the SQL scripts so others don't have to recreate them. Do not provide screenshots of tables or results.
Include test output, in text formatted as a table, to show both what you're currently getting as well as what your desired output should be. Search for "ascii table generator" on your favorite search engine - there are several that are extremely easy to use.
An example question, including an MCVE framework
I want to get the total count of the number of ducks in each pond.
The ponds table:
CREATE TABLE ponds ( PondName varchar(30) , DuckName varchar(30) );
Some sample data:
INSERT INTO ponds (PondName, DuckName) VALUES ('Golden', 'Daffy') , ('Walden', 'Daisy');
My query so far:
SELECT COUNT(DuckName) FROM ponds;
The output I'm getting:
╔═══════╗ ║ Value ║ ╠═══════╣ ║ 2 ║ ╚═══════╝
The output I'd like to get:
╔════════╦═══════╗ ║ Pond ║ Count ║ ╠════════╬═══════╣ ║ Golden ║ 1 ║ ║ Walden ║ 1 ║ ╚════════╩═══════╝
Yes, the above sample question would be considered "too localized" for our site; this is just a quick example