我想使用Codeigniter框架从4个表中选择数据。这4个表具有相似的列结构。我想得到与某年和月相对应的表格数据。
这是我的表结构:
表t1
:
accid uid month year ccbalance
--------------------------------------------------------
101 19 May 1996 4545
-----------------------------------------------------
101 19 sept 1998 1500
--------------------------------------------------------
表t2
:
accid uid month year insbalance
--------------------------------------------------------
102 19 May 1995 2059
-----------------------------------------------------
102 19 july 1998 2500
--------------------------------------------------------
表t3
:
accid uid month year ccbalance
--------------------------------------------------------
109 19 June 1999 10000
-----------------------------------------------------
109 19 Aug 1990 1500
--------------------------------------------------------
表t4
:
accid uid month year ccbalance
--------------------------------------------------------
105 19 Aug 1995 10000
-----------------------------------------------------
105 19 May 1995 3333
--------------------------------------------------------
如果我选择May 1995
,我想得到这个结果:
accid uid month year ccbalance
--------------------------------------------------------
105 19 May 1995 3333
102 19 May 1995 2059
答案 0 :(得分:0)
Codeigniter 2.0和3.0中没有内置联合函数
您可以创建自己的SQL查询并执行它:
$sql="(SELECT * from t1 where month='May' AND year=1995)
UNION
(SELECT * from t2 where month='May' AND year=1995)";
$query = $this->db->query($sql);
return $query->result();
有关mysql union语法的更多信息,请找here(官方文档)