为什么用UNION显示这样的数据



我正在代码点火器中进行UNION,我希望数据显示为这样。

[array] => Array
(
[0] => stdClass Object
(
//Table 1
[id_tecnico] => 1698
[date] => 2018-02-12
[nro] => M49320
[start] => 15:15
[end] => 17:45
[comment] => ok.
[total] => 2.5
)
[1] => stdClass Object
(
//Table 2
[id_tecnico] => 1698
[nro] => M49317
[date] => 2018-02-12
[activity] => meeting
[comment] => meeeting about nothing 
[TotalHrs] => 0.67
)
)

我的模型中有以下查询,其中我对表Maintenance进行查询,但我也使用相同的WHERE对表Activities进行查询

$this->db->select('p.name,s.date,s.nro,d.start,d.end,d.comment,d.total,m.machine');
$this->db->from('Tecnico_Seguimiento as t');
$this->db->join('personal as p','p.Codigo = t.id_tecnico');
$this->db->join('MAN_SeguimientoDetalle as d','d.id_detalle = t.id_detalle');
$this->db->join('MAN_Seguimiento as s','s.idMan_Tecnico = d.id_man_tecnico');
$this->db->join('MAN_Solicitud as m','m.NroSolicitud = s.NroSolicitud');
$this->db->where('t.id_tecnico',$id);
$this->db->where('s.date >=',$minvalue);
$this->db->where('s.date <=',$maxvalue);
$query1 = $this->db->get_compiled_select();

$this->db->select('act.nro as nroAct, act.date as fechaAct,act.activity,act.comment as commnetAct, act.TotalHrs, act.orden, act.date as dateAct, act.id_tecnico ');
$this->db->from('MAN_Actividades as act');
$this->db->where('act.date >=',$minvalue);
$this->db->where('act.date <=',$maxvalue);
$this->db->where('act.id_tecnico <=',$id);
$query2 = $this->db->get_compiled_select();
return $this->db->query($query1." UNION ".$query2)->result();

通过这个查询,我得到了这些值

[array] => Array
(
[0] => stdClass Object
(
[name] =>  HUGO
[date] => 2018-02-20
[nro] => M49301
[start] => 17:45
[end] => 19:30
[commet] => ok.
[total] => 1.75
[machine] => Torno
)
[1] => stdClass Object
(
// Here should be the fields of the table activities
[name] => M49321
[date] => 2018-02-12
[nro] => meeting
[start] => meeting about nothing
[end] => 1
[comment] => 49321
[total] => 17:43:00
[machine] => 1698
)
)

应该是[activity] => meeting,而不是[nro] => meeting。我不知道为什么只有一些第一个选择,或者我应该编辑select,只做一个。我感谢所有提供的信息和帮助

我希望我已经很好地解释了我

不能对每个查询中的不同字段执行UNION,SELECT子句中的字段在两个查询中必须相同。

相关内容

  • 没有找到相关文章

最新更新