Reputation: 6298
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
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:
Upvotes: 1