2

I am a MSSQL user now I am converting my database to MySQL,
I am writing following query in MySQL.

select col1 as [My Column] from table1

Error : You have an error in sql syntax

Himanshu
  • 31,810
  • 31
  • 111
  • 133
Mandeep Singh
  • 2,016
  • 7
  • 19
  • 32

4 Answers4

4

You have a syntax error because the escape character (delimiter) is different from MSSQL. You need to use backtick instead of brackets. eg,

select col1 as `My Column` from table1

MySQL => backtick
MSSQL => bracket

John Woo
  • 258,903
  • 69
  • 498
  • 492
1

Remove []

select col1 as MyAliasName from table1

Or

select col1 as `My Alias Name` from table1
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
1

Aliasses work the same in mysql, but you need to use other delimiters: Instead of:

select col1 as [My Column] from table1;

use

select col1 as ´My Column´ from table1;

or without any delimiters if the table/column-name doesn't contain any special characters:

select col1 as MyColumn from table1;

Borniet
  • 3,544
  • 4
  • 24
  • 33
0
select col1 as my_column from tablename;
ShoibAhamed
  • 327
  • 1
  • 5
  • 16