0

The query is the following:

SELECT group,mailId FROM marketinggroups ORDER BY group ASC

and here is the CREATE code of the table marketinggroups

CREATE TABLE `marketinggroups` (
`group` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT 'gruppo',
`mailId` INT(10) NOT NULL DEFAULT '0' COMMENT 'id della mail'
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB;

And here is the MySql error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group,mailId FROM marketinggroups ORDER BY group ASC' at line 1

What's wrong with this query? I have used the same syntax in other tables with success.

Humayun Shabbir
  • 2,961
  • 4
  • 20
  • 33
mark
  • 939
  • 2
  • 13
  • 36
  • 3
    `group` is a reserved word. It needs to be escaped (surrounded by backticks). Or better yet, use a different name. – Gordon Linoff Aug 02 '14 at 12:15
  • 1
    Would also recommend using a different column name but just to add, other than escaping the name, you can also order by 1 asc, since group is the first column in the select list (you can also omit "asc" since that is the default order) – Brian DeMilia Aug 02 '14 at 12:23

2 Answers2

1

group is a SQL reserved word. Having a column with a reserved names make you this issue. So rename your column name to something else.

1

You can rewrite the query like below using (backtics), as group is a mysql reserved keyword.

SELECT `group`, `mailId` FROM `marketinggroups` ORDER BY `group` ASC
fortune
  • 3,361
  • 1
  • 20
  • 30