mysql - Always return 1 even when there is no table related object -
i query database table joined related table example: want show styles , join mixes style show 0 mixes if thst style don't have mixes related.
here 2 tables:
first mixes table
create table `mixes` ( `mixes_id` int(11) not null auto_increment, `datepublic` date default null , `timelenght` time default null , `title` varchar(255) default 'no-title-yet' , `dwnlsize` varchar(45) default '? megabytes', `quality` char(10) default '? kbits/s', `style_id` int(3) unsigned zerofill default null, `collection_id` int(3) unsigned zerofill default '001', `liendwnld` varchar(255) default null, `vidlink` varchar(255) default null, `artistefeat` varchar(255) default null, `slugmixtitle` varchar(100) default null, `cache` enum('0','1') default null, primary key (`mixes_id`), unique key `title_unique` (`title`), unique key `liendwnld_unique` (`liendwnld`), unique key `slugmixtitle` (`slugmixtitle`), key `style_index` (`style_id`), key `collection_index` (`collection_id`) ) engine=innodb default charset=latin1 ; alter table `mixes` add constraint `collectionmustexist` foreign key (`collection_id`) references `collection` (`collection_id`), add constraint `stylemustexist` foreign key (`style_id`) references `style` (`style_id`);
then style table
create table `style` ( `style_id` int(3) unsigned zerofill not null auto_increment, `imgmixcat` varchar(255) default null, `namemixcat` varchar(45) default null, `descmixcat` varchar(255) default null, `slugmixcat` varchar(45) default null, `hidemixcat` int(11) not null default '0', primary key (`style_id`), unique key `namemixcat_unique` (`namemixcat`), unique key `slugmixcat` (`slugmixcat`) ) engine=innodb default charset=latin1 auto_increment=20 ;
and current query:
select count(style.style_id) count, namemixcat, style.style_id, descmixcat, hidemixcat, slugmixcat, imgmixcat style style left join mixes mixes on style.style_id = mixes.style_id group style.style_id order style.style_id asc
so make return 1 when there no mixes related style?
Comments
Post a Comment