For want of a comma

March 1st, 2007 by comment

my kingdom was lost.

Watch those commas. A little SQL detail that can bite you:

SELECT
SID
NAME,
ETC
FROM MYTABLE

MySQL, and presumably other databases, is just fine with that statement. It’ll alias the field SID to NAME. If you name columns explicitly with the AS keyword, a missing comma will yield an error:

SELECT
SID AS studentid <--baaarf
NAME AS studentname,
ETC AS studentetc
FROM MYTABLE

Comments

One Response to “For want of a comma”

  1. Catherine Devlin says:


    Yup, I’m an Oracle DBA and have been thrown into confusion by this many times. It’s best when you’re selecting a bunch columns, trying to send the results somewhere else, and get an error about “not enough columns”, and you can’t tell why…

Got something to say?


cheap research papers