Some of the site's questions rule that something must (or must not) be printed to the output. My question is, in the case of SQL, what really is the output?

The select command returns result-sets, which can be a 1x1 array of "string". The print command, as defined in a specific implementation (sql server), returns a string to the user.

So select 'Hello world!' and print 'Hello world!' are both valid commands that return the same string to the user, albeit in different places.

So, which of these are considered "printing" in terms of golf SE? Could it be both?

  • 2
    \$\begingroup\$ I'd think either would be allowed, like how there's alert, print, and console.log for JS. \$\endgroup\$ Commented Jul 28, 2020 at 17:28
  • 6
    \$\begingroup\$ When we decide on an answer it goes here. codegolf.meta.stackexchange.com/questions/2447/… There's an INPUT case for SQL but no OUTPUT case. \$\endgroup\$
    – Joshua
    Commented Jul 28, 2020 at 18:38
  • \$\begingroup\$ Are you talking about MSSQL, T-SQL, MySQL/MariaBD, SQLite, PostgreSQL or some other? \$\endgroup\$ Commented Jul 29, 2020 at 11:45
  • \$\begingroup\$ I personally use mssql/tsql, but I guess such choice would be present in other dbmss too. \$\endgroup\$ Commented Jul 29, 2020 at 11:48
  • \$\begingroup\$ @GeorgeMenoutis MySQL doesn't support the print statement. The closest you have is SELECT 'Hello world!' as '' (just SELECT 'Hello world!' works but shows the text twice, once on the column name and once on the content). Or \! echo 'Hello world!'; but that's just calling the echo statement from the console (stackoverflow.com/a/61375812). \$\endgroup\$ Commented Jul 29, 2020 at 14:18
  • \$\begingroup\$ @IsmaelMiguel, but that way you will have a leading newline. Why not “--skip-column-names, -N Do not write column names in results.”? i.sstatic.net/xwPNY.png \$\endgroup\$
    – manatwork
    Commented Jul 30, 2020 at 11:33
  • \$\begingroup\$ @manatwork There are rules in place about flags. And I doubt that all SQL implementations (or most) have those flags. Or they do have it, but also have the print statement. Also, I doubt that people will be running the scripts directly from the console. They will probably have an online environment to try it, or a website with an SQL IDE, where that option doesn't exist. But, if an answer for MySQL specifies it, why not? Maybe should be part of the rules? \$\endgroup\$ Commented Jul 30, 2020 at 11:39
  • \$\begingroup\$ Also works when running SQL script file. PostgreSQL has “-t, --tuples-only Turn off printing of column names and result row count footers, etc.”, but have to also use “-A, --no-align Switches to unaligned output mode.” There your empty alias trick doesn't work. In SQLite there is “-[no]header Turn headers on or off.” but the no is the default anyway. i.sstatic.net/1Hmjn.png \$\endgroup\$
    – manatwork
    Commented Jul 30, 2020 at 12:10

1 Answer 1


We have countless examples of highly upvoted answers sending SQL output to either the results pane (via SELECT) or to the messages pane (via PRINT), depending on which works the best and is shorter for a particular challenge.

Both are acceptable.

(This uses terminology from MS SQL Management Studio, other platforms/clients likely have equivalents.)

Note other outputs are possible as well, such as outputting graphical results to the spatial results pane.


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