As I am a beginner to stackoverflow community, Can someone help me with following questions?
- What are the possible ways to write queries and give answers to stackoverflow questions?
- Do I need to create databases with sample data locally from scratch to answer them?
- Is there any online tools that can write queries with dummy data help to answer the questions quickly?
Really appreciate your answers on this.
CodePudding user response:
I believe you are looking for something like this
- What are the possible ways to create code samples and give answers to stackoverflow questions?
-
Here you can create objects, create data and write code simulate "the answer" to some question.
Do I need to create local projects from scratch to answer them?
I am not sure what are you asking here but NO.
Is there any online tools that can create code samples with dummy data (in case of a SQL question) help to answer the questions quickly?
CodePudding user response:
This question and also possible answers are likely to some part opinion based (and this is something which should be avoided on Stackoverflow). But some things to answer your question should be generally correct and not opinion based. So whenever you ask a SQL question, take care of following points:
- Describe your issue as most precise and clear as possible, but avoid to add unnecessary or confusing information
- Tag the DB you are using
- Always show the sample input and expected outcome
- Show what you tried to solve your issue (in best case, you already created a query that is almost correct) and explain why it's not working yet.
- If possible, provide a DB fiddle to allow people to replicate your issue.
There will be further points (maybe someone will provide another answer or comment this one), so overall you can just ask yourself "Have I done everything possible to make it possible that people can understand my issue and provide a possible solution?" and make sure your question is asked in a way which answers this question with "Yes!". Let's make a very simple example: Your sample input is:
Table yourtable
column1 | column2 |
---|---|
1 | 2 |
2 | 2 |
3 | 4 |
0 | 10 |
And you want to find this outcome:
column1 | column2 |
---|---|
2 | 2 |
0 | 10 |
The rows you want to receive should have identic values in column1 and column2 OR
column1 = 0.
Now you also tell us that you tried this query:
SELECT column1, column2
FROM yourtable
WHERE column1 = column2
AND column1 = 0;
But this query doesn't find any rows. Remember this is a really simple example and of course, you would have found the reason. But since we just want to illustrate the way of asking questions, now you have already shown us sample input, expected outcome and your failing idea how to get this result. Now, you could also add a fiddle example with all this information. db<>fiddle
Well, perfect! Now people can easily understand and replicate your issue and just need to think about a solution and check this solution using the fiddle you've shown. And then you will likely get a correct answer in a short time and don't have to ask plenty of questions because your question was too unclear.
So in this simple case, someone would tell you that you need OR
instead of AND
.
SELECT column1, column2
FROM yourtable
WHERE column1 = column2
OR column1 = 0;
CodePudding user response:
After googling for an answer, I could find one site to write queries with sample data in it (sample data already uploaded there). It is very helpful to quickly find answers. So, I am gonna post it here.
https://data.stackexchange.com/stackoverflow/query/edit/1604254