id | c_id | type
light_id | light_name
hard_id | hard_name
select t.*, if(l.light_name is not null, l.light_name, h.hard_name) as type_name from `table` t
left outer join light l on l.light_id = t.c_id
left outer join hard h on h.hard_id = t.c_id
where
if(t.type = 1, l.light_id = t.c_id, l.light_id < 0)
or
if(t.type = 2, h.hard_id = t.c_id, h.hard_id < 0)