The question is as simple as the title says,But here is one logic. Here is my code
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
Here is data in this table
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
cmp_brand is prefixed with some their ids like 123_ and 789_ in my case. Now if i search for NIKE, so I have two parameters,one is NIKE and other is id_NIKE.where id may be 123 or 456 or any other.So for NIKE search i have two parameters,one is brand=NIKE and other is cmp_brand =123_NIKE (i cancatenate id with brand name automatically)
What i want is
IF cmp_brand is '' then compare with brand ELSE compare brand AND cmp_brand.
Here is what i tried,both not working
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'))