An employee
An employee

Reputation: 6298

mysql compare enum

Here is a table i have

CREATE TABLE `CUSTOMERSTATUSTYPES` (
  `CustomerStatusId` int(1) unsigned NOT NULL auto_increment,
  `CustomerStatusName` enum('ACTIVE','SUSPEND','TERMINATE','CANCEL') default NULL,
  PRIMARY KEY  (`CustomerStatusId`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

When i write

GROUP BY ... WHERE cst.CustomerStatusName<>'TERMINATE' ;

i get a syntax error

ERROR 1064 (42000): 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 'WHERE cst.CustomerStatusName<>'TERMINATE'' at line 1

How do i correctly check this?

Upvotes: 0

Views: 1463

Answers (2)

Philip Reynolds
Philip Reynolds

Reputation: 9392

You either need to put the WHERE clause before the GROUP BY clause, or you need to use the HAVING keyword.

See here for more info:

http://www.databasejournal.com/features/mysql/article.php/3469351/The-HAVING-and-GROUP-BY-SQL-clauses.htm

Upvotes: 1

Greg
Greg

Reputation: 321688

The WHERE clause must come before the GROUP BY clause.

Upvotes: 3

Related Questions