MySQL Self Join Not All Rows included -


i have problem working out self join.

i have following table:

create table  `test`.`tablen` ( `id` int(10) unsigned not null auto_increment,   `group` int(10) unsigned not null,   `item` int(10) unsigned not null, `data` varchar(45) default null, primary key  (`id`) )  engine=innodb;  insert `test`.`tablen` (`group`,`item`,`data`) values  (1,100,'aaa'), (1,200,'bbb'), (2,100,'ccc'), (2,200,'ddd'), (3,100,'eee'); 

what need run query, outputs data each 'item' in single row.

the query have got is:

select t1.`group`, t1.`item`, t1.`data`, t2.`item`, t2.`data` tablen t1 left join tablen t2 on t2.`group`=t1.`group` 1=1 , t1.item = 100 , t2.item = 200 group t1.`group`; 

the problem is, returns 2 rows (group 1 , group 2). need return row group=3, though there no entry item=200.

how can please.

put t2.item = 200 condition join clause.

select t1.`group`, t1.`item`, t1.`data`, t2.`item`, t2.`data` tablen t1 left join tablen t2 on t2.`group`=t1.`group` , t2.item = 200 1=1 , t1.item = 100 group t1.`group`; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -