I would like to ask a question on Stack Overflow which includes a table of data from a MySQL database. What is the best way to include a table of data in a question?


3 Answers 3


Some people like ASCII Art. Though it's annoying to type in:

| Username  | Password  | Email_Addr |
| Username1 | Password1 | Email 1    |
| Username2 | Password2 | Email 2    |
| Username3 | Password3 | Email 3    |
| Username4 | Password4 | Email 4    |
| Username5 | Password5 | Email 5    |

As someone that answers a lot of SQL questions the best way In my opinion to include a table of data is as follows.

Username varchar(20) PRIMARY KEY,
Password varchar(30),
Email_Addr varchar(100)

SELECT 'Username1','Password1','Email 1' UNION ALL
SELECT 'Username2','Password2','Email 2' UNION ALL
SELECT 'Username3','Password3','Email 3' UNION ALL
SELECT 'Username4','Password4','Email 4' UNION ALL
SELECT 'Username5','Password5','Email 5' 

It gets tedious very quickly adding quotes onto strings, inserting commas and removing vertical bars, underscores and other such artefacts in order to set up a test table to answer the question.


If you don't want to create ASCII art you could upload an image. Simply create the table yourself (spreadsheets work well for this) and then upload a screenshot of the table.

# Sample Table Image #

Another route would be to create a table in a google spreadsheet and then use the publish as a web page option to create a link to it.

  • 4
    No. This is not a good idea. It just increases the amount of typing that potential answerers have to do. Commented May 6, 2011 at 18:01
  • While I also appreciate DDL/DML to setup SQL questions and am glad you included that as an answer (+1), sometimes a visual representation would be useful. In particular, users new to SQL may not know how to generate table creation/population SQL. I'd certainly prefer picture of their table over the vague two sentence descriptions I often see. Commented May 6, 2011 at 19:37
  • An image also works for any tabular data whether it is database related or not. Commented May 6, 2011 at 19:43
  • Yes true it's definitely better than a vague sentence! My -1 is locked in now so I can't remove it. Shame the support in the markdown editor is so non existent for tables as discussed in this related feature request Commented May 6, 2011 at 21:58
  • @Martin, I edited the question. I'm not sure, but I think that means you can up-vote it back to zero. Commented May 9, 2011 at 18:49

Not the answer you're looking for? Browse other questions tagged .