Skip to content
Advertisement

MySQL: cannot add constant field at start of SELECT. Error 1064

Using MariaDB v. 10, I try to add a custom constant as the first column of my SELECT query, before all other columns *. This results in the generic syntax error 1064.

For example:

If I select only some columns, it works:

And it also works if I use * to select all columns, but put my constant column after it:

How can I do a SELECT 'some constant', * FROM my_table to avoid this strange error?

Advertisement

Answer

You can only use SELECT * if it’s the first thing in the SELECT list. If it’s mixed in with other values, you need to use a table name or alias, so do

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement