I have a problem working out a Self Join.
I have the 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 INTO `test`.`tableN` (`Group`,`Item`,`data`)
VALUES
(1,100,'aaa'),
(1,200,'bbb'),
(2,100,'ccc'),
(2,200,'ddd'),
(3,100,'eee');
What I then need to do is run a query, that outputs the data for each 'item' in a single Row.
The Query I have got is:
SELECT
t1.`Group`,
t1.`item`,
t1.`data`,
t2.`item`,
t2.`data`
FROM tableN t1
LEFT JOIN tableN t2 ON t2.`group`=t1.`group`
WHERE 1=1
AND t1.item = 100
AND t2.item = 200
GROUP BY t1.`Group`;
The problem is, this only returns 2 rows (Group 1 and Group 2). I need it to also return a row for Group=3, even though there is no entry for item=200.
How can I do this please.