CASE in WHERE in mysql -
this question has answer here:
- case in clause in mysql 1 answer
the question simple title says,but here 1 logic. here 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 data in 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 prefixed ids 123_ , 789_ in case. if search nike, have 2 parameters,one nike , other id_nike.where id may 123 or 456 or other.
what want is
if cmp_brand '' compare brand else compare brand , cmp_brand.
here tried
select thumb inf_brand_images is_active=1 , case when cmp_brand = '' brand='$brandname' else cmp_brand='$id_$brandname' end
use or in clause:
select count(id) tot inf_brand_images is_active=1 , ((cmp_brand = '' , brand='$brandname') or (cmp_brand='$id_$brandname')
possible duplicate:
Comments
Post a Comment