How to select child and parent categories by type

How can i select child and parent categories where type = 1 ?

For example:

TV (type = 0) -> LED (type = 1) -> QLED (type = 1) -> 32inc (type = 0)

TV (type = 0) -> LED (type = 1) -> QLED (type = 1) -> 24inc (type = 1)

Phone (type = 1) -> LG (type = 1) -> A100 (type = 1)

Phone (type = 1) -> LG (type = 1) -> C300 (type = 1)

Im looking to get result like

LED -> QLED

LED -> QLED -> 24inc

Phone -> LG -> A100

Phone -> LG -> C300

If parent/child is not type = 1 shouldn`t exist in return results but their child should exist in result if type = 1

SQL Fiddle

        CREATE TABLE `menu` (
      `id` int(11) NOT NULL,
      `name` varchar(255) NOT NULL,
      `main_cat` int(11) NOT NULL,
      `room` int(11) NOT NULL COMMENT ' 0 = False, 1 = True',
      `type` int(11) NOT NULL COMMENT ' 0 = False, 1 = True',
      `sort_order` int(11) NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;


    INSERT INTO `menu` (`id`, `name`, `main_cat`, `room`, `type`, `sort_order`) VALUES
    (21, 'TV', 0, 1, 0,  1),
    (22, 'LED', 21,  0, 1, 1),
    (23, 'QLED', 21, 0, 1, 0),
    (24, '24inc', 23, 0, 1, 0),
    (25, '32inc', 23, 1, 0, 0),
    (26, 'Phone', 0, 0, 1, 2),
    (27, 'LG', 26, 0, 1, 2),
    (28, 'A100', 27, 0, 1, 1),
    (29, 'C300', 27, 0, 1, 1),
    (55, 'PC', 0, 1, 1, 3),
    (56, 'HP', 55, 0, 1, 2);


    ALTER TABLE `menu`
      ADD PRIMARY KEY (`id`);

        SELECT 
      m1.id AS main_id, m1.name AS main_name, 
      m2.id AS sub_id, m2.name AS sub_name, 
      m3.id AS subsub_id, m3.name AS susub_name 
    FROM menu m1
      LEFT JOIN menu m2 ON m2.main_cat = m1.id
      LEFT JOIN menu m3 ON m3.main_cat = m2.id
    WHERE m1.main_cat = 0

Answer

Just add your where clause in inner SQL:

 SELECT 
      m1.id AS main_id, m1.name AS main_name, 
      m2.id AS sub_id, m2.name AS sub_name, 
      m3.id AS subsub_id, m3.name AS susub_name 
    FROM menu m1
      LEFT JOIN (SELECT * FROM menu where type=1) m2 ON m2.main_cat = m1.id
      LEFT JOIN (SELECT * FROM menu where type=1) m3 ON m3.main_cat = m2.id
    WHERE m1.main_cat = 0

Or use my method if I understand carefully

 SELECT * FROM (
 SELECT m1.name as name1, m2.name as name2 FROM menu m1
 LEFT JOIN menu m2
 on m1.id = m2.main_cat
 where m2.type = 1
) A 
left join (
 SELECT m1.name as name1, m2.name as name2 FROM menu m1
 LEFT JOIN menu m2
 on m1.id = m2.main_cat
 where m2.type = 1
) B
on A.name2 = b.name1

Or in a better way use temporary table

 CREATE TEMPORARY TABLE tmpTable SELECT m1.name as name1, m2.name as name2 FROM menu m1
 LEFT JOIN menu m2
 on m1.id = m2.main_cat
 where m2.type = 1;
 
 SELECT A.name1, A.name2,B.name2 FROM tmpTable A 
left join tmpTable B
on A.name2 = b.name1
  

EDIT================== Add type qualifier for rows:

SELECT A.name1, A.name2, B.name2 FROM (
 SELECT m1.name as name1, m2.name as name2 FROM menu m1
 LEFT JOIN menu m2
 on m1.id = m2.main_cat
 where m1.type = 1 and m2.type = 1
) A 
left join (
 SELECT m1.name as name1, m2.name as name2 FROM menu m1
 LEFT JOIN menu m2
 on m1.id = m2.main_cat
) B
on A.name2 = b.name1