Home > front end >  Do I need to create sample tables with data always to recreate the issue in questions?
Do I need to create sample tables with data always to recreate the issue in questions?

Time:06-11

As I am a beginner to stackoverflow community, Can someone help me with following questions?

  1. What are the possible ways to write queries and give answers to stackoverflow questions?
  2. Do I need to create databases with sample data locally from scratch to answer them?
  3. 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

  1. What are the possible ways to create code samples and give answers to stackoverflow questions?
  1. Do I need to create local projects from scratch to answer them?

    I am not sure what are you asking here but NO.

  2. 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:

  1. Describe your issue as most precise and clear as possible, but avoid to add unnecessary or confusing information
  2. Tag the DB you are using
  3. Always show the sample input and expected outcome
  4. 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.
  5. 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

  • Related