CASE em WHERE CLÁUSULA no MYSQL
A pergunta é tão simples quanto o título diz: Mas aqui está uma lógica. Aqui está o meu código
CREATE TABLE `inf_brand_images` (
`id` bigint(99) NOT NULL AUTO_INCREMENT,
`brand` varchar(255) NOT NULL,
`thumb` text NOT NULL,
`is_active` int(2) NOT NULL DEFAULT '1',
`cmp_brand` varchar(1024) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6458 DEFAULT CHARSET=latin1
Aqui estão os dados nesta tabela
ID | brand | thumb |is_active| cmp_brand
1 | NIKE | a.png | 1 |
2 | DUNHILL| b.png | 1 |
3 | NIKE | c.png | 1 | 123_NIKE
4 | NIKE | d.png | 1 | 789_NIKE
O cmp_brand é prefixado com alguns de seus IDs, como 123_ e 789_ no meu caso. Agora, se eu procurar por NIKE, então eu tenho dois parâmetros, um é NIKE e outro é id_NIKE.where id pode ser 123 ou 456 ou qualquer outro. = 123_NIKE (cancelo a identificação com o nome da marca automaticamente)
O que eu quero é
IF cmp_brand is '' then compare with brand ELSE compare brand AND cmp_brand.
Aqui está o que eu tentei, ambos não funcionando
SELECT thumb
FROM inf_brand_images
where is_active=1 AND
CASE WHEN cmp_brand = '' THEN brand='NIKE'
ELSE cmp_brand='123_NIKE' END
SELECT thumb
FROM inf_brand_images
where is_active=1 AND
((cmp_brand = '' AND brand='NIKE') OR (cmp_brand='123_NIKE'))